Fork me on GitHub
#shadow-cljs
<
2018-03-22
>
grounded_sage00:03:58

I'm venturing into using shadow-cljs. Everything seems to just work right up until I try to apply styles. Not sure how I would go about it from here.

grounded_sage00:03:01

(ns starter.browser
   (:require [rum.core :as rum]
             [react-native-web :as react-native :refer (View Text)]))



(rum/defc hello-world []
  [:div
   [Text "hello there"]
   [:h3 {:style {:color "blue"}} "Edit this and watch it change!"]])

grounded_sage00:03:35

I'd like to apply style to the Text element

justinlee02:03:45

@grounded_sage that shouldn’t have anything to do with shadow

grounded_sage02:03:22

Yea I've been playing around with it. Can get things to work with Reagent. It appears it's to do with React component interop with Rum

justinlee02:03:09

are you saying that the Text element imports and displays but it doesn’t style the way you expect?

grounded_sage02:03:40

That snippet of code works as is. However when it comes to styling I can't style it.

justinlee02:03:00

I never got interop to work right with rum which is why I switched to reagent, honestly. I quite liked rum otherwise. It was just never clear how to pass back and forth between react components.

grounded_sage02:03:03

When using Reagent I can do this and then it works

(def Text (r/adapt-react-class Text))

(defn app []
  [:div
   [Text {:style {:color "blue" :font-size "40px"}}   "hello"]

grounded_sage02:03:47

Yea my preference is Rum however this is making me think otherwise 😞

justinlee02:03:09

I feel you. I preferred the syntax of rum in many ways.

justinlee02:03:11

so try one thing: try [Text {:style “color: blue”} “Hello there”]

justinlee02:03:27

it may be that rum doesn’t do the style mapping on custom components

justinlee02:03:53

as a general matter, it doesn’t make sense to do that--I assume this is some kind of react native thing

grounded_sage02:03:32

There appears to be some cache stuff going on. I'm getting old errors and code rendering that no longer exists in the file.

justinlee03:03:07

one thing that can catch me: make sure your stuff is compiling. sometimes the heads-up-display will disappear and your old code will just be sitting there while your existing code has a compile error

justinlee03:03:17

otherwise shadow is actually really good about caching

grounded_sage03:03:20

For some reason shadow-cljs is flat out not working anymore lol. Have no idea what I've done now 😛

justinlee03:03:33

what’s it doing?

justinlee03:03:56

try restarting the server and see what you get on the terminal

grounded_sage03:03:43

How do you restart?

grounded_sage03:03:05

It says it is a server error

grounded_sage03:03:17

I've retried downloading the quickstart

grounded_sage03:03:55

It doesn't work. On my old one it just throws a heap of errors that no longer exist. On my reagent one no changes to the file are being reflected but it is serving it as it was before

justinlee03:03:30

can you look at your terminal history and tell me how you started shadow?

grounded_sage03:03:37

I've just been using this from the quickstart npx shadow-cljs clj-repl

justinlee03:03:45

and you just ran that once and left it up?

justinlee03:03:02

i believe you should just be able to kill that process and then restart it

grounded_sage03:03:07

No I've stopped and started on different files

justinlee03:03:38

so kill everything and then go to your browser and reload the page

justinlee03:03:49

if it reloads, there’s an old shadow process up somewhere that you’ll need to kill

grounded_sage03:03:39

I've done a full restart of computer. This is the error I am getting on the Rum on

[:app] Build failure:
The required namespace "starter.browser" is not available.

[2018-03-22 13:31:05 - WARNING] stale websocket client, please reload client :app
[2018-03-22 13:31:23 - WARNING] stale websocket client, please reload client :app
[2018-03-22 13:31:40 - WARNING] stale websocket client, please reload client :app

justinlee03:03:18

the issue is that it can’t find your source code, I think. the build failure is causing all of these issues

grounded_sage03:03:57

Weird thing is that the namespace was there. Making a change in the file and saving seems to have fixed it by triggering it to recompile

justinlee03:03:04

are you starting from the same directory as before

justinlee03:03:14

that is super weird

justinlee03:03:24

I don’t really understand what’s going on. thomas is asleep so he won’t be back online for a while. actually you’re behind me so you’ll probably still be up when he gets up

grounded_sage03:03:52

Ok seems that calling [Text .... inside the Rum one was throwing a warning in the console. But it was still rendering

thheller08:03:32

@grounded_sage The required namespace "starter.browser" is not available. is it possible your ns form is busted?

thheller08:03:48

the warning/error for this currently ends up in the wrong place I think

grounded_sage08:03:27

I'm not sure what the error was. Everything seemed fine. I've actually moved past this error and am currently trying to adapt React classes to be used with Rum.

thheller08:03:58

ok. I don't know anything about rum but it should work identically as in other tools. if it doesn't please let me know.

grounded_sage08:03:46

Yea rum is working and so is reagent. It's just there isn't a standard way to interop with React components in Rum. So I'm searching the web for solutions. I actually feel like I am getting somewhere with Shadow CLJS over all the other options. Thanks!'

👍 4
thheller08:03:36

@grounded_sage you might be able to just create the React Element directly? don't know how Rum deals with this but (:require ["react" :refer (createElement)]) then (createElement Text #js {:foo "bar"} ...)

thheller08:03:53

getting children to work properly might be an issue then though

sundbp09:03:18

Hi. If I add a new file and namespace in a shadow-cljs project, should that file be picked up without restarting a shadow-cljs watch session?

thheller09:03:52

well only if you also require that file somewhere

thheller09:03:59

just creating it wouldn't have any effect

sundbp09:03:37

I’m not really seeing this. so I have x.cli requiring x.foo that now requires x.api (this last one is new). I can’t seem to get it to try to compile this one

thheller09:03:39

hmm did you require before creating the file? that might result in a situation where the worker gets stuck

sundbp09:03:47

i probably did, yes

thheller09:03:02

hmm yeah that would be an issue. let me look into that.

sundbp09:03:03

then out of luck and a restart?

thheller09:03:44

what was the last message you got?

thheller09:03:53

The required namespace "starter.browser" is not available. like this?

sundbp09:03:20

it’s nodejs: The required namespace "permafrost.api" is not available, it was required by "permafrost/health.cljs".

sundbp09:03:59

hm. a restart of the watch has same thing. could the state be messed up in .shadow-cljs ?

sundbp09:03:08

or is it pilot error somewhere else

thheller09:03:07

just to be sure you have a src/permafrost/api.cljs directly next to src/permafrost/health.cljs?

thheller09:03:16

unlikely for the cache to be messed up

sundbp09:03:46

» ll src/cljs/permafrost/api.clj src/cljs/permafrost/health.cljs                                                                                                                                                                                      09:32:53
Permissions  Size User   Group Date Modified Name
.rw-r--r--    704 sundbp staff 22 Mar  9:28  src/cljs/permafrost/api.clj
.rw-r--r--  1.6Ki sundbp staff 22 Mar  9:21  src/cljs/permafrost/health.cljs

thheller09:03:56

its a .clj file

sundbp09:03:04

ha - old habbit!

thheller09:03:44

I could totally add a warning for this

sundbp09:03:45

so this is a try if require before file picks it up - seems like it! thanks

sundbp09:03:04

that’d be awesome - I can see myself doing it again..

sundbp09:03:12

[:pf] Build failure:
The required namespace "permafrost.api" is not available, it was required by "permafrost/health.cljs".

[:pf] Compiling ...
[:pf] Build completed. (168 files, 59 compiled, 0 warnings, 42.48s)

sundbp09:03:22

all good - thanks. it’s an awesome tool!

👍 4
thheller09:03:13

[:browser] Build failure:
The required namespace "demo.run-test" is not available, it was required by "demo/browser.cljs".
"demo/run_test.clj" was found on the classpath. Should this be a .cljs file?

sundbp09:03:33

that’s great - very user friendly!

grounded_sage10:03:26

Does shadow cljs do dead code elimination? I feel like I am accumulating too many libraries just for small pieces of functionality.

thheller10:03:03

for CLJS? yes.

grounded_sage10:03:00

Is it possible to do something like this?

Rum will call sablono.compiler/compile-html in its macro. You could add a sablono.compiler namespace (a .clj file) into your project and create a compile-html function which calls Hicada with the config you like. This namespace will take precedence over any CLJ namespace on your classpath.

grounded_sage10:03:42

I feel like I am muddying the waters a lot here lol. I would love it if I could just somehow use React Native Web with Rum library and be able to have it all built in Node on Netlify xD

grounded_sage10:03:35

I feel like I need to get my Clojure foo a lot better and hack my own version of Rum together 😕

thheller10:03:12

I would just give up on the hiccup thing altogether

thheller10:03:46

don't need a compiler for hiccup if you are direclty using something better instead

grounded_sage10:03:14

The problem is Rum uses Sablono internally. Which doesn't work with self hosted.

thheller10:03:15

(html/div
      (html-section-header (name build-id))
      (html/div
        (html/button
          {:onClick #(conv/transact! this (watch-start! build-id))
           :disabled (any? worker)}
          "watch start")
        (html/button
          {:onClick #(conv/transact! this (watch-stop! build-id))
           :disabled (nil? worker)}
          "watch stop")
        (html/button {:onClick #(conv/transact! this (db/compile! build-id))} "compile")
        (html/button {:onClick #(conv/transact! this (db/release! build-id))} "release"))
      (html/pre {:ref (::dom-ref this)}
        (with-out-str
          (pprint data))))

thheller10:03:50

looks basically like hiccup, doesn't require a compiler.

thheller10:03:13

emits basically what the hiccup compiler would emit

grounded_sage10:03:32

React native for web uses View Text TouchableOpacity etc

rauh10:03:20

I think you should post the stacktrace here as well (which you posted in #rum)

thheller10:03:24

so create a (rn/view ...) (rn/text ...) wrapper

grounded_sage10:03:29

Hmm i see. So shadow has markup etc.

thheller10:03:06

the markup stuff is currently only built for the react-dom side

thheller10:03:16

could adapt it just as easily for RN

thheller10:03:41

the point is to call functions instead of this hiccup-ish datastructure that needs to be compiled to be performant

thheller10:03:29

ah ... so you ran into an actual problem

thheller10:03:34

Exception: No namespace: sablono.core found
    clojure.core/the-ns (core.clj:4128)
    clojure.core/ns-publics (core.clj:4155)
    clojure.core/ns-publics (core.clj:4155)
    shadow.build.macros/find-macros-in-ns (macros.clj:32)
    shadow.build.macros/find-macros-in-ns (macros.clj:30)

thheller10:03:43

most likely this means that the macro ns failed to load

grounded_sage10:03:14

That was when I attempted to overwrite the sablono.compiler using Hicada

thheller10:03:45

don't know what that is about but it should work as in any other tool

grounded_sage10:03:20

But in all honesty I'm really looking a solution I can run entirely in one VM be is JVM or Node so that I can deploy to Netlify.

thheller10:03:55

do you mean running the code in the JVM or compiling the code in the JVM?

thheller10:03:35

does netlify support java?

grounded_sage10:03:37

I'm kind working on creating some holy grail JAMstack solution in Clojurescript.

grounded_sage10:03:04

They have docker images with common build tools and allow others to provide build tool solutions.

grounded_sage10:03:42

So you can basically pick your build tool. Set what command is required to build it. Then point them at a github/gitlab repo.

grounded_sage10:03:08

Then any changes you push they run the build and autodeploy to global CDN

grounded_sage10:03:12

Poor mans devops

grounded_sage10:03:55

I think it is a great solution for front ends even for larger productions. You cleanly separate front and backend.

thheller10:03:33

but how is this related to the hiccup stuff?

thheller10:03:18

if java is available you can just run npx shadow-cljs release my-app and then have it copy your :output-dir to wherever?

grounded_sage11:03:18

I don't know I'm confused as I don't know enough about all the processes. I am assuming that most options with netlify would just have one option in the docker images. So like either Node, JVM/Leiningen, JVM/Boot etc

thheller11:03:18

so it appears that java is installed. we don't need lein or boot

thheller11:03:33

but back up a second. what are you actually trying to do?

thheller11:03:15

you have a repo that should run some command, create a .js file that is then copied somewhere and loaded in a webpage?

grounded_sage11:03:34

Have some kind of build process where I can output everything into some target folder (html, css, js, images, svg etc) Whilst using React Native for Web so that I can write code the same way (as close as possible) between doing a web app and native app.

thheller11:03:36

ok shadow-cljs currently only supports JS and doesnt do the rest. but you can use whatever other tool you want for those

thheller11:03:56

say shadow-cljs generates your output into public/js

thheller11:03:07

have another tool generate things into public/css and so on

thheller11:03:20

you then copy the public folder and you are done?

grounded_sage11:03:31

I think shadow cljs could work.

thheller11:03:47

npx shadow-cljs release your-build is all you'd need to run

grounded_sage11:03:28

I really think my main issue is how I get Rum to come to the party lol.

thheller11:03:35

so the problem is that Rum doesn't understand react-native?

thheller11:03:14

FWIW (:require [shadow.markup.react :as html :refer ($)] ["react-native" :as rn :refer (Text View)]) then in render ($ Text {:style style-obj} "hello world")

thheller11:03:43

$ is just sugar for calling createElement directly

thheller11:03:21

I could add a shadow.markup.react-native :as rn then (rn/text {:style ...} "foo") would just work

grounded_sage11:03:51

Just normal React components

thheller11:03:05

I don't do any react-native dev so I have never written any utils for it

grounded_sage11:03:08

React Native for Web creates normal react components. https://github.com/necolas/react-native-web

grounded_sage11:03:30

It's just a way to create code that can work on React Native or React (web)

grounded_sage11:03:27

So you aren't writing View for one codebase and Div for the other when it's exactly the same thing visually.

thheller11:03:20

yeah so the problem is getting that to work with rum? I can guarantee that the above shadow.markup example I posted will just work

thheller11:03:28

since it doesn't have to do all this complex macro magic

grounded_sage11:03:28

Anyways this works fine in Reagent and I believe Shadow-cljs is the right tool. No point me cluttering this channel with an issue that is basically unrelated:)

thheller11:03:44

sure reagent should deal with this as well

grounded_sage11:03:51

I don't think Shadow.markup does it for me because it does defstyled approach. All good. I will continue plugging away at this Rum problem haha

thheller11:03:57

I guess I don't understand how react-native-web works if there code example doesn't have a single reference to react-native-web

thheller11:03:30

aaaaaaaah ... babel-plugin-react-native-web ...

grounded_sage11:03:45

Yea haha. Tripped me up as well. I was like WHERE IS THIS COMING FROM. haha

thheller11:03:25

well thats BS ...

grounded_sage11:03:21

Well this works flawlessly

(ns starter.core
    (:require [reagent.core :as r]
              [react-native-web :as react-native :refer (Text View)]))

(def Text (r/adapt-react-class Text))
(def View (r/adapt-react-class View))

(defn app []
  [:div
   [View {:style {:background-color "red" :height "100px" :width "100px"}
          :accessibility-role "main"}
    [Text {:style {:color "blue" :font-size "40px"}}   "hello"]].....

grounded_sage11:03:46

But that is using Reagent 🙂

thheller11:03:53

whats wrong with reagent?

thheller11:03:39

["react-native" :as react-native :refer (Text View)]

grounded_sage11:03:48

I find Rum to be much nicer. Except this not working with React components is making me think otherwise haha

thheller11:03:13

and in your build config :js-options {:resolve {"react-native" {:target :npm :require "react-native-web"}}} 😉

thheller11:03:36

if you want to truly use the same code

thheller11:03:53

basically all that does is rewrite ["react-native" :as react-native :refer (Text View)] to ["react-native-web" :as react-native :refer (Text View)]

grounded_sage11:03:07

Well at the moment it's just a learning exercise. My focus is all web but this should help me bridge that.

grounded_sage11:03:33

Yea awesome. So much better than a babel plugin haha

thheller11:03:37

doesn't do anything to the reagent/rum situation but might make things cleaner if you actually have a second build for a RN app

grounded_sage11:03:44

Ah now I see where I am running up against. I tried this ages ago which is what was causing issues I first brought up in this channel. https://github.com/tonsky/rum/issues/20#issuecomment-282471141

grounded_sage11:03:18

sablono is clj. So I was calling clj in cljs haha. So it seems all solutions would require me to do some clj if I am to use Rum.

grounded_sage12:03:47

Not quite sure whether this could solve my problem but do you think I could use this https://shadow-cljs.github.io/docs/UsersGuide.html#clj-run

thheller12:03:05

what problem?

grounded_sage12:03:55

Just needing to run some clj to do the class adapting in Rum.

grounded_sage12:03:36

It looks like if I could use sablono.util and adapt them I could then just pull them in.

thheller12:03:46

I'm sorry I really don't understand what you are trying to do. Do you have some code I can look at?

thheller12:03:14

but no clj-run is only meant to call clojure core directly. not as part of a build or anything.

grounded_sage12:03:00

Ah ok. Yea it probably won't work then. That comment #20 has the code I am referring to.

grounded_sage12:03:07

Thank you for your time! I think my best bet is just go with Reagent and move along. 🙂

thheller12:03:21

If you create a full repo with an example of what you are trying to do I can look at it

thheller12:03:35

just one ns doesn't tell me enough to figure it out

thheller12:03:45

> When you write [(.-Route js/ReactRouter) {:name "home"} ] sablono tries to parse it as tag, something of form [:div attrs & children]. > Just create component with interop syntax, e.g. (js/ReactRouter.Route #js {:name "home"}). Do not put in a vector as first element (but as child — in sablono terms — it’s ok)

thheller12:03:46

so the issue is that sablono unconditionally tries to parse [Text ...] as something

thheller12:03:23

reagent has special syntax for [:> NativeThing ...]. maybe sablono does too?

grounded_sage12:03:50

I believe that is just shorthand for adapt-react-class which Rum doesn't have as a utility built in.

thheller12:03:45

seems like a pretty big issue if rum/sablono doesn't support any native react components/classes

thheller12:03:00

it shouldn't require any hacks to make this work

jmckitrick14:03:47

Ok, here goes. I’m spending part of the day trying shadow and hopefully documenting the cider setup, if I can get it working.

jmckitrick14:03:30

So, just to clarify where I left off… if I have a project with a backend serving a re-frame SPA, I’m still better off as one project, right? Even with shadow?

jmckitrick14:03:44

I’m already excited about the browser caching fix. FF drives me nuts with that sometimes, and now Chrome does it as well.

jmckitrick14:03:55

First, I’d like to fix the broken clojars link.

jmckitrick14:03:57

But I’m not sure what to do with the link to the image

thheller14:03:03

broken clojars link?

jmckitrick14:03:32

Actually, the image below it

jmckitrick14:03:50

I see ‘the artifact can be found at’ and a broken image link below that.

thheller14:03:30

I have no idea what you are talking about?

thheller14:03:58

oh you are talking about the broken images in the README? wonder why they are broken

thheller14:03:02

didn't even notice this

thheller14:03:19

it appears to be something on githubs end. https://img.shields.io/npm/v/shadow-cljs.svg this source link works

thheller14:03:46

its just really slow so maybe github just runs into a timeout

jmckitrick14:03:09

The original gave me a plain text error message.

thheller14:03:46

ah ok .. the guide had one too

thheller14:03:14

should be a temp github issue

jmckitrick14:03:48

I just added [thheller/shadow-cljs] to my project.clj, and :lein true in shadow-cljs.edn and then I run lein run -m shadow.cljs.devtools.cli compile and I’m getting class not found….

jmckitrick14:03:57

I’ll dig some more

thheller14:03:10

which class?

thheller14:03:44

you should really start out without the lein integration. so much simpler to just leave lein in its own world and not mess with it

jmckitrick14:03:48

It went farther this time, not sure why…

thheller14:03:07

that being said it should work fine so if you get errors please tell me

jmckitrick14:03:36

Let’s go back to no lein…

jmckitrick14:03:03

I do have separate clj cljc and cljs files under src… hopefully that won’t bite me just yet.

thheller14:03:28

that is totally fine. I do too.

jmckitrick15:03:33

ok, so I got the deps installed and the build succeeded.

jmckitrick15:03:53

I’m looking at a ‘shadow-cljs’ page with release snapshots links….

jmckitrick15:03:39

I guess I need to serve up some other assets…

thheller15:03:58

thats the internal webserver intended for later UI work

thheller15:03:23

if you want to get a webserver for your build you can configure it here: https://shadow-cljs.github.io/docs/UsersGuide.html#browser-http-server

jmckitrick15:03:39

Ok, so I added a line for :main :entries, but the build is not finding that namespace.

jmckitrick15:03:06

Do I need an entrypoint first?

thheller15:03:08

do you have the file in the correct place?

jmckitrick15:03:32

It works under the lein build, but maybe shadow isn’t finding it?

thheller15:03:49

depends on the :source-paths you have configured

thheller15:03:27

you lein config probably has a some :source-paths configured. those need to be configured in shadow-cljs.edn as well

jmckitrick15:03:54

I’m up and running!

jmckitrick15:03:18

I had to comment out 2 npm react components… I’ll get to that part next.

jmckitrick16:03:31

Once I import those components successfully, do I use the [:> foo] notation for Reagent component creation?

jmckitrick16:03:18

So here’s what I’m seeing when I load my page with the react components I’ve imported…

jmckitrick16:03:34

GET net::ERR_ABORTED

jmckitrick16:03:47

And there’s a whole list of other components.

jmckitrick16:03:10

And I’m also using a minified react for dev… that’s giving me a warning.

thheller16:03:29

why would it abort?

thheller16:03:47

maybe some adblocker or so interfering?

jmckitrick16:03:36

Let me turn it off

jmckitrick16:03:51

Though it’s never been an issue before.

jmckitrick16:03:00

Wait, those classes are not found in my local directory….

jmckitrick16:03:17

js/cljs-runtime/module$node_modules$….

jmckitrick16:03:37

A lot of them are, but not the 2 I required.

thheller16:03:24

react-avatar-editor doesn't depend on lodash

jmckitrick16:03:39

Well, some other things might… but I did discover that neither of these 2 components are in the manifest.edn.

jmckitrick16:03:12

Though the react components and many others are.

thheller16:03:44

rewind please ... lets first look at this net::ERR_ABORTED thing.

thheller16:03:51

there is no reason for this to happen

jmckitrick16:03:23

First of all, I’m removing code related to this component, doing a hard refresh, and I’m still seeing warnings related to it in the code. The page refuses to render. After a trivial change and hot reload, the page renders (with the components disabled)

thheller16:03:24

that probably means that the component was not the cause

jmckitrick16:03:24

But there’s a handful of components that are not in the manifest, but are required by the 2 that I need. And of course, those 2 are missing as well.

jmckitrick16:03:32

But they are in the package.json.

thheller16:03:34

this works perfectly fine for me

thheller16:03:09

what is the other component you are talking about?

thheller16:03:35

package.json doesn't matter .. only thing that matters is things you actually reference in your code

jmckitrick16:03:44

ok. I built your project, and it works. Thanks for that. I see differences in versions, so I bumped mine up, and everything broke.

thheller16:03:02

it is absolutely possible that your node_modules directory is messed up. npm does that frequently.

jmckitrick16:03:03

I’m reverting to my versions, and I’m going to try that. Then I’ll revert yours to the same as mine, and try that

jmckitrick16:03:17

I just blew that away and reinstalled. Let’s see how far I get…

thheller16:03:52

there might be caching issues but I didn't have any in a long time

thheller16:03:12

just in case you should kill the shadow-cljs process and delete the .shadow-cljs/builds directory

jmckitrick16:03:26

I was about to ask how to clean

jmckitrick17:03:59

So the manifest (and cljs-runtime dir) still does not have the modules I need

jmckitrick17:03:03

I don’t get it….

thheller17:03:36

are you sure you are looking at the correct directory and everything?

jmckitrick17:03:22

Pretty sure…

jmckitrick17:03:01

The path is… public/js/cljs-runtime/

thheller17:03:40

so I just added lodash.debounce to verify that it works and it works just fine

thheller17:03:59

thats the module$node_modules$lodash_debounce$index.js thats missing for you

thheller17:03:39

are you sure the file really doesn't exist?

thheller17:03:17

I'm still suspicious about the NET_ABORTED. that is usually caused by some browser extension.

jmckitrick17:03:43

ok, problem solved. All my fault, lol.

jmckitrick17:03:23

I tried to make my shadow config mirror my lein cljs-build config, and I got them out of sync. So the build directories were incorrect.

jmckitrick17:03:53

I tremendously appreciate the time you took to whip up that demo. That helped me narrow it down.

jmckitrick17:03:05

Did you see my PR for cider docs? 😁

thheller17:03:13

I'll look at the emacs stuff tomorrow

thheller17:03:35

shouldn't be too hard to integrate it directly into cider

thheller17:03:43

so we don't need any of this special stuff

lwhorton17:03:52

i just read through the whole user guide and one thing I didnt see mentioned was devdependencies. in lein, for example, I can specify a dev profile that has its own dependencies for things like binaryage/devtools and piggieback. how does shadowcljs handle this scenario?

thheller17:03:37

doesn't have to. the builds control what is used. having :dependencies on the classpath does not affect what a build does.

thheller17:03:45

so its fine to always have them available

jmckitrick17:03:11

Is there a way to use a debug React build, or else squash the warning I see in the console? @thheller

thheller17:03:11

note that it will probably get support for this at some point because it becomes relevant when packaging libraries

👍 4
thheller17:03:20

but it currently doesn't do that so it is not required

thheller17:03:54

@jmckitrick the warning is a bit annoying yes but unfortunately no. everything is correct though. it just complains because it doesn't understand what shadow-cljs is doing. still need to bug the react people about their bad detection method

thheller17:03:19

you are using the react debug build. react just doesn't expect that it is minified.

jmckitrick17:03:22

Not a problem.

thheller17:03:40

shadow-cljs release will use their proper release version so the warning will go away then

jmckitrick17:03:46

Now that I have this working, I’m wondering if I should try lein integration…

lwhorton18:03:46

is there a way to suppress warnings that stem from not-my-code? for example, something requires cuerdas and cuerdas uses NaN instead of js/NaN

thheller18:03:44

yeah by updating the cuerdas version. that was fixed a while ago.

lwhorton18:03:33

but in general, is there a way to make these disappear? I don’t really know who is requiring some of these transitive deps, and I really dont want to do manual one-off updates and pray that I dont break some api, ya know?

thheller18:03:10

well warnings are kinda important so no there is no way to turn them off

thheller18:03:56

since figwheel and other tools only show warnings once they tend to get ignored and forgotten

thheller18:03:11

and then people wonder why things break over time

lwhorton18:03:47

i see your premise, but if the third-party code is out of my control it will be incredibly annoying to have those warnings always visible and obfuscating issues within my own app code

thheller18:03:22

I do see your point. I'll think about it. Maybe just not repeat the warnings on recompile, just show them once on watch start or so.

thheller18:03:51

you can just fix it by adding [funcool/cuerdas "2.0.5"] to your deps

jmckitrick18:03:59

So I’ve just converted a colleague (at a different shop) to shadow-cljs. But he’s asking if there’s a way to alias ‘preact’ as a replacement for ‘react’ and ‘react-dom’ dependencies.

thheller18:03:27

:js-options {:resolve {"react" {:target :npm :require "preact"}}}

thheller18:03:31

same for react-dom

jmckitrick18:03:43

Perfect. I knew I saw something like that somewhere. Let me give it a shot…

thheller18:03:07

wasn't there a preact/compact or so? might need to use that

jmckitrick18:03:26

‘preact-compat’

thheller18:03:00

yeah exactly, same way it works in webpack. just written slightly different

thheller18:03:12

resolve: {
        alias: {
            'react': 'preact-compat',
            'react-dom': 'preact-compat',
            // Not necessary unless you consume a module using `createClass`
            'create-react-class': 'preact-compat/lib/create-react-class'
        }
    }

thheller18:03:38

I never actually tested this for preact but it should work

thheller18:03:26

:js-options
{:resolve
 {"react" {:target :npm :require "preact-compat"}
  "react-dom" {:target :npm :require "preact-compat"}}}

jmckitrick18:03:38

I’m running it now… fingers crossed

thheller18:03:18

@jmckitrick there might be a cache issue. I don't think :resolve currently invalidates the cache

jmckitrick18:03:31

Ok… I’m seeing errors, yes.

jmckitrick18:03:47

so blow away .shadow-cljs/builds?

thheller18:03:52

yes I didn't account for :resolve in the cache code for this

thheller18:03:00

yes, try that.

thheller18:03:41

I'll fix this now

thheller18:03:45

hmm no it seems to invalidate correctly. I can switch it while a build is running

thheller18:03:15

ah .. it invalidated CLJS correctly but not JS

thheller18:03:52

so if there is a JS lib that used react it will continue using react

jmckitrick18:03:55

I’m seeing an error message about forceUpdate

jmckitrick18:03:21

@kanwei blow away your .shadow-cljs/builds directory

kanwei18:03:22

this is without any :exclusions in the deps

thheller18:03:32

did you add the resolve config for create-react-class?

jmckitrick18:03:44

I did not.. let’s see…

thheller18:03:12

:js-options
{:resolve
 {"react" {:target :npm :require "preact-compat"}
  "react-dom" {:target :npm :require "preact-compat"}
  "create-react-class" {:target :npm :require "preact-compat/lib/create-react-class"}}}

jmckitrick18:03:40

I’m up and running!

kanwei18:03:15

it still seems to be loading react from cljsjs

kanwei18:03:20

how do I exclude that from re-frame?

thheller18:03:49

shadow-cljs doesn't support cljsjs so thats impossible 😛

thheller18:03:11

its probably this

thheller18:03:09

these files just exist since most CLJS projects still expect to use cljsjs

kanwei18:03:28

@thheller 1. great job on this, I'm pleasantly surprised

kanwei18:03:42

2. I'm struggling to understand why the advanced compiled files are so much smaller than boot-cljs

kanwei18:03:53

is it because it's running the npm through the optimizer too?

thheller18:03:38

thats hard to say without knowing what you boot-cljs build did

kanwei18:03:10

pretty vanilla re-frame app with cljsjs

kanwei18:03:27

(cljs :optimizations :advanced
                 :compiler-options {:output-wrapper true
                                    :pseudo-names true
                                    :pretty-print true})

thheller18:03:35

the problem with cljsjs is that these are pre-bundled packages

thheller18:03:52

pre-bundle means that they may include certain dependencies

thheller18:03:59

and then another package might include them again

thheller18:03:08

so you end up with the code loading twice

thheller18:03:23

:pseudo-names true
:pretty-print true

thheller18:03:44

these are debug settings. never use that for a production build 🙂

thheller18:03:48

so there is your reason

thheller18:03:18

shadow-cljs release app --debug should be equivalent to that boot-cljs config

justinlee18:03:30

hey @thheller just out of curiosity why do you minify during development?

thheller18:03:05

I rely on closure :simple removing the conditional and only leaving one of the requires

thheller18:03:36

otherwise your page would load the production and dev versions. it would only use the dev version but I still don't like loading stuff I don't need

thheller19:03:07

this pattern by the react folks is super annoying

thheller19:03:21

but yeah I optimize due to conditional requires .. and its basically free so why not

thheller19:03:08

bunch of tracking for keeping track of conditional requires

thheller19:03:28

I hope the world moves to ES6 quickly where this mess isn't allowed anymore 😛

thheller19:03:47

although I'm sure they'll find a way to mess it up again

justinlee19:03:50

it’s so painful that something as dumb as a module system causes so much grief

thheller19:03:42

well cljs isn't much better if you think about it. can't do conditional require either but sometimes you just want to.

thheller19:03:55

proper namespace support is huge though

justinlee19:03:33

at least there is just ONE way to do it in cljs

justinlee19:03:47

every new js module proposal reminds me of https://xkcd.com/927/

kanwei19:03:17

now trying to see if inferno-compat will work

kanwei19:03:34

getting stuck on create-react-class

kanwei19:03:04

:js-options {:resolve {"react"     {:target :npm :require "inferno-compat"}
                                  "react-dom" {:target :npm :require "inferno-compat"}
                                  "create-react-class" {:target :npm :require "inferno-create-class"}}}

thheller19:03:34

hmm that might be an issue due to the cljsjs compat namespace

thheller19:03:49

this assigns the React.createClass to whatever create-react-class returned

thheller19:03:51

this is probably not was inferno-create-class is

thheller19:03:19

create a cljsjs/react.cljs file in your project

thheller19:03:44

and copy the file above and just remove the create-react-class require and set below

thheller19:03:32

(ns cljsjs.react
  (:require ["react" :as react]))
(js/goog.exportSymbol "React" react)

thheller19:03:49

this should do it. inferno-compat already provides the React.createClass

kanwei19:03:18

what path is cljsjs/react.cljs?

kanwei19:03:20

in src-cljs?

thheller19:03:41

if you source path is src-cljs then src-cljs/cljsjs/react.cljs yes

kanwei19:03:21

hmm still

Uncaught TypeError: reagent.impl.util.create_class.call is not a function

thheller19:03:58

which reagent version is that?

thheller19:03:53

can you bump to a newer reagent version?

thheller19:03:02

hmm inferno-create-class does not export a function it exports inferno-create-class/createClass

thheller19:03:24

so the :resolve trick won't work since that differs from what create-react-class exports

kanwei19:03:21

i hate tooling

thheller19:03:39

you are pushing the limits here

kanwei19:03:16

someone has to 🙂

thheller19:03:23

you could create a inferno-create-class-compat package

thheller19:03:38

that just does module.exports = require("inferno-create-class").createClass;

thheller19:03:26

that might do it but I have never used inferno so I don't know what else is hiding in there

kanwei19:03:53

cool thanks

kanwei19:03:59

probably just stick to preact-compat

justinlee22:03:33

@thheller i seem to have gotten my shadow into a bad state. shadow-cljs server start never returns and it doesn’t seem to finish a compile or recompile. if i kill that and do a single build, that works. i’ve already blown away .shadow-cljs but i’m not sure where else there may be state lurking

justinlee22:03:40

oh sorry I guess you have to run a watch command separately in addition to the server. still it is weird that server start does not return

grounded_sage23:03:13

Woot. Got things working. Nearly built a whole website now using React Native for Web.