shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
Galagora 2020-10-05T00:10:49.275200Z

OK, so FWIW, I put the same minimal reproducible example up https://github.com/galagora/clonode. I couldn't get Figwheel to work either. I guess I'll just have to use something with better Node.js support, https://www.tweag.io/blog/2019-05-09-inline-js/ 😉

devn 2020-10-05T01:16:35.276Z

ClassCastException: clojure.lang.KeywordLookupSite$1 incompatible with clojure.lang.Named I keep getting these on shadow-cljs watch

devn 2020-10-05T01:16:52.276300Z

it stems from some business in shadow around cljs_hacks

devn 2020-10-05T01:19:25.276700Z

ClassCastException: clojure.lang.KeywordLookupSite$1 incompatible with clojure.lang.Named
        clojure.core/namespace (core.clj:1597)
        clojure.core/namespace (core.clj:1597)
        shadow.build.cljs-hacks/shadow-resolve-var (cljs_hacks.cljc:155)
        shadow.build.cljs-hacks/shadow-resolve-var (cljs_hacks.cljc:147)
        cljs.analyzer/resolve-existing-var (analyzer.cljc:1276)
        cljs.analyzer/resolve-existing-var (analyzer.cljc:1271)
        cljs.compiler/fn--9175 (cljs_hacks.cljc:740)
        cljs.compiler/fn--9175 (cljs_hacks.cljc:717)

devn 2020-10-05T01:19:35.277Z

It doesn’t happen every time.

xfyre 2020-10-05T02:23:21.277100Z

so now I have

(defn dev-render-root {:dev/after-load true} []
  (shadow/render-root "DcnetApp" (r/as-element [app-root]))
  )
it’s called after I update the code, as expected
[Sun Oct 04 2020 19:17:50.501]  LOG      load JS dcnet_app/screens/home.cljs
[Sun Oct 04 2020 19:17:50.507]  LOG      load JS dcnet_app/appnav.cljs
[Sun Oct 04 2020 19:17:50.508]  LOG      call dcnet-app.ios.core/dev-render-root
but the screen doesn’t get updated. anything else I might be missing?

xfyre 2020-10-05T03:02:51.277400Z

I think something’s off with the bundler. I tried two other methods (directly calling .forceUpdate and updating ratom within the root component). It does trigger re-rendering, but still displays old version of the code. I’ll let you know if I figure it out.

rberger 2020-10-05T07:15:16.285400Z

Anyone familiar with being able to use https://shoelace.style/getting-started/installation in a shadow-cljs project? I can’t seem to just simply require components even though its shipped as an npm package. Do I need to do some webpack thing first? (their installation docs seem to imply that). Or is there some special path I need to use?

rberger 2020-10-05T07:19:33.286900Z

I have tried (:require ["@shoelace-style/shoelace" :refer [SlButton]]) and (:requre ["@shoelace-style/shoelace" :as sl]) and I end up with nil for SlButton or sl/SlButton

thheller 2020-10-05T09:00:11.288500Z

@devn do you maybe use shadow-cljs embedded in some CLJ app in combination with some kind of classloader magic or tools.namespace?

thheller 2020-10-05T09:01:05.289100Z

@rberger read https://shadow-cljs.github.io/docs/UsersGuide.html#_using_npm_packages about the default exports. I don't know for this case but it might be (:requre ["@shoelace-style/shoelace" :default SLButton])

thheller 2020-10-05T09:01:48.289800Z

but from the package name I gather its about CSS which shadow-cljs does not handle. so it might be webpack only?

victorb 2020-10-05T09:04:49.291800Z

Is there any built-in way of combining watch and release? Basically just want a way of running release every time the files change. watch will call compile on file change, as I understand it, so if there is a way of getting it to run release instead?

thheller 2020-10-05T09:05:20.292400Z

no

🙏 1
localshred 2020-10-05T14:09:38.293800Z

not native to shadow in particular, but if you use watchman-make you can do anything you want after files are changed e.g. watchman-make -p './src/***/**.cljs' -t release https://facebook.github.io/watchman/docs/watchman-make.html

localshred 2020-10-05T14:10:09.294100Z

(where release would be a target in your Makefile to run shadow-cljs release {target} )

victorb 2020-10-05T16:11:31.294700Z

Thanks @localshred, I opted for the inotifywait route as I already had that installed and didn't need to download anything new 🙂

localshred 2020-10-05T16:30:37.294900Z

oh for sure, there's a billion watchers out there. yay unix :)

🎉 1
rberger 2020-10-05T19:17:24.295500Z

@thheller I was able to get it to import with:

(:require ["@shoelace-style/shoelace/dist/custom-elements/index.js" :refer [defineCustomElements setAssetPath SlButton]])
It ends up with an html custom element (web component) now I still have to figure out how to access the element after doing:
(.define js/customElements "sl-button" SlButton)
SlButton is defined as a class, but sl-button is not defined. I probably just need to learn more how web components work with reagent.

devn 2020-10-05T19:25:49.295800Z

I don’t think that’s my situation, but either way, do you have any suggestions for catching what’s actually happening here?

thheller 2020-10-05T20:10:25.296Z

ah if its web components you just do [:sl-button ...] like any other regular dom element

thheller 2020-10-05T20:11:20.296200Z

thats why the :refer and stuff may not actually exist because you don't need it if it already self-registers

thheller 2020-10-05T20:11:24.296400Z

not a clue

rberger 2020-10-05T20:17:03.296600Z

Oh, I didn’t try with the : Now that I try that, it does inject <sl-button>… into the DOM now, but I’m getting a

Uncaught ReferenceError: regeneratorRuntime is not defined
index.js:2654 Uncaught ReferenceError: regeneratorRuntime is not defined
    at initializeComponent (index.js:2654)
    at _connectedCallback (index.js:2944)
    at HTMLElement.connectedCallback (index.js:3049)
    at commitPlacement (react-dom.development.js:8835)
    at commitAllHostEffects (react-dom.development.js:18656)
    at HTMLUnknownElement.callCallback (react-dom.development.js:150)
    at Object.invokeGuardedCallbackImpl (react-dom.development.js:200)
    at invokeGuardedCallback (react-dom.development.js:257)
    at commitRoot (react-dom.development.js:18914)
    at eval (react-dom.development.js:20419)
But at least that is something I can track down now hopefully. Thanks again for your help! Oh, I didn’t try with the

thheller 2020-10-05T20:23:48.296800Z

that likely means you are including transpiled code from babel

thheller 2020-10-05T20:25:06.297100Z

I think a require for regenerator-runtime might be enough

rberger 2020-10-05T20:30:11.297300Z

Ok. The package has two styles of distriubtions. This custom-elements path that at least let me import: > is a direct build of the custom element that extends `HTMLElement`, without any lazy-loading. The custom elements bundle does not apply polyfills, nor automatically define each custom elements. This may be preferred for projects that will handle bundling, lazy-loading and defining the custom elements themselves. The default path that I couldnt get to import: > The `dist` type is to generate the component(s) as a reusable library that can be self-lazy loading, such as https://www.npmjs.com/package/@ionic/core.

rberger 2020-10-05T20:36:28.297600Z

Adding regeneratorRuntime as a refer item didn’t change the behavior I saw a babel issue that suggested adding

&lt;script src="<https://unpkg.com/regenerator-runtime@0.13.1/runtime.js>"&gt;&lt;/script&gt;
to the index.html and that did make it work! Will go back and see how to do that thru npm/require. Yay! Now to see if this web components actually help life in reagent or not…

devn 2020-10-05T20:59:01.297800Z

Is there any way to look at a log of what shadow-cljs does?

devn 2020-10-05T21:10:22.298Z

im completely stumped right now

thheller 2020-10-05T22:21:36.298200Z

it is extremely unlikely that this is actually a shadow-cljs problem

thheller 2020-10-05T22:21:42.298400Z

this is deep inside the clojure core code

thheller 2020-10-05T22:21:56.298600Z

so it is much more likely something goin on in your JVM that shouldn't be

thheller 2020-10-05T22:22:01.298800Z

how are you running things?

thheller 2020-10-05T22:23:06.299Z

(:require ["regenerator-runtime"]) should do it in case you didn't try .. you said "refer" which would be incorrect

thheller 2020-10-05T22:23:21.299200Z

(maybe npm install regenerator-runtime first of course)

thheller 2020-10-05T22:23:31.299400Z

but the script tag is fine too I guess

thheller 2020-10-05T22:24:15.299600Z

if you are connected over nREPL it might be the nREPL doing stuff

rberger 2020-10-05T22:25:18.299800Z

Yep, (:require ["regenerator-runtime"])`` works great. Preferred to <script> tag Thanks again!

devn 2020-10-05T23:51:52.300Z

@thheller it’s not always inside the clojure core code. I wish I could get a smaller way to reproduce, but: The project has 3 primary source directories: “shared” (cljc code) “src” (clojure code) “ui-src” (clojurescript code) There is a project.clj which specifies all 3 of these source paths in its source-paths key. This project.clj requires the latest version of clojurescript. In addition, there is a package.json and a shadow-cljs.edn. The shadow-cljs.edn has 3 builds in it, all of which are specified with :entries [the.ns]

devn 2020-10-05T23:52:56.300200Z

The shadow watch is run with npx — shadowcljs 2.11.4 is specified in the package.json