Fork me on GitHub
#shadow-cljs
<
2023-03-16
>
Jakub Holý (HolyJak)09:03:59

Hello! I am struggling to figure out how to split my app in two modules with different lifecycles - a main.js with most of the code, which changes rarely and thus can be compiled once and reused, and a session.js which needs to be compiled on-demand for each user, and which depends on stuff from my main ns <> the main module. I have declared two modules with the correct entrypoints but currently whenever I release , both are recompiled and I suspect that main may change between these compilations (f.ex. depending on what api exactly session uses in the case, as Closure tries to optimize and move functionnality around). I.e. I have 2 problems: 1. (assumption) clients cannot cache main.js b/c it may differ for each client, 2. compilation takes longer b/c main is also recompiled. Is there any solution? Thank you! 🙏 I was thinking of compiling just main into a library but that does not really help - when we compile session, shadow/closure would likely not understand what is already present in the library and does does not need to be compiled into session.js itself… (Context: we use the cljc clara-rules, which only supports compiling rules into a “session” in Clojure; but we want to do this not at compile time but at runtime, when users supply dynamically built rules so the idea is to compile most of frontend into a rather static package + compile session.js with the clara session based on the provided rules on demand, and ship that to the frontend to combine with the main bundle and run rules there.)

thheller10:03:38

what you are after is conceptionally not possible

thheller10:03:36

also likely optimizing for the wrong thing. I mean how big is main.js?

thheller10:03:43

but yeah :advanced means such things are not possible

👍 2
Jakub Holý (HolyJak)10:03:45

Main with advanced is some 400k

p4ulcristian13:03:21

Hello! I am loving ClojureScript and Shadow-cljs aswell. Use them everyday. Unfortunately though, using @react-spring/web doesn't work for me (all the other libraries do, useGesture, useDropzone, anything.) I get this error:

Closure compilation failed with 2 errors
--- node_modules/@react-spring/shared/dist/index.js:2
Transpilation of 'Computed fields' is not yet implemented.
--- node_modules/@react-spring/shared/dist/index.js:2
Transpilation of 'Member references this or super' is not yet implemented.
Any help is appriciated, thank you :)

thheller14:03:16

those are errors from the closure compiler, seems the code is using features it doesn't support. assuming you are on the latest versions there isn't much you can do

p4ulcristian14:03:14

I'll check webpack if I gave up on this. The interesting thing is, that it worked for a month, without turning off the compiler. Now I deleted node_modules , npm install again, and here we are. The even funnier thing is, the project already runs on a domain, so I don't really know what did I messed up. I dont want to give up my clojure compiler + shadow-cljs node and javascript , because it's so beautiful and comfortable. Will check back if I found a solution :)

thheller15:03:24

well if you delete node_modules and npm installed you might have gotten a new react-spring/web version

👍 2
thheller15:03:31

maybe try downgrading that

👍 2
p4ulcristian15:03:24

I tried that, before asking any question I spent 2 hours with it. But I think it'll be your webpack solution after all, if I succeed.

thheller16:03:01

looks like you didn't load the webpack output?

thheller16:03:39

see the blog post, need to load the webpack output file before the shadow-cljs output

nivekuil05:03:31

react-spring works for me, don't recall doing anything fancy

p4ulcristian23:03:36

https://github.com/paul931224/closure-compiler-error I made a minimal example, maybe someone figures it out. But version 9.6.1 does work, my mistake was trying to downgrade with ^9.6.1 not understanding what ^ means . Version 9.7.1 does not work for some reason. Thanks for the help, I tried out webpack and to compile with babel, but I don't want to lose the simplicity of shadow-cljs so downgrading was the solution as thheller mentioned :)

nivekuil14:03:16

I guess 9.7 broke some stuff looking at the react-spring issue tracker 😞

nivekuil14:03:49

so maybe try :output-feature-set :es2020 in shadow config?

nivekuil14:03:22

oh, wait that's just the output js

thheller14:03:23

those are supported. thats not what the error is complaining about

thheller14:03:37

its likely that they just also started using some other stuff that is not yet supported

thheller14:03:53

or maybe changed their build so it isn't getting transpiled anymore

lilactown15:03:16

I have a persistent issue that suddenly started occurring recently where my cypress tests (build using :npm-module) fail to load in the test runner with the following error message

Namespace "goog.debug.Error" already declared.
Doing a release build works, but I cannot use compile or watch

lilactown15:03:44

I've upgraded to 2.22.2 and it persists

thheller16:03:23

well thats the issue you always get for trying to load the same namespace twice

thheller16:03:34

goog.debug.Error just usually happens to be the first one loaded

thheller16:03:52

so looks like cypress might be trying to reload the code when already loaded before?

lilactown18:03:16

maybe... it only happens when I try and load all of the files that :npm-module builds. If I only load one built ns file, it works fine

thheller18:03:00

can't tell you. I don't know anything about cypress and how it is loading stuff. maybe you have some old files sitting arround somewhere that shouldn't be there?

thheller18:03:21

maybe trying to load 2 builds or something?

frankitox20:03:59

Anyone knows if it's possible to run shadow-cljs in a "content script", in a chrome/firefox extension?

frankitox20:03:57

I have something like this in my manifest

"content_scripts": [
    {
      "matches": ["*://*.],
      "js": ["public/assets/shadow/js/main.js"]
    }
  ],

frankitox20:03:33

It successfully loads the file, but that main.js file tries to load some other js files which are blocked by Firefox

frankitox20:03:48

The idea would be to run a shadow-cljs REPL per Firefox tab

thheller20:03:59

no. shadow-cljs is a JVM process. at most the tab could connect to that remotely, but even then the user would need to run it locally?

frankitox21:03:13

I want to write an extension and use a cljs REPL while doing it

thheller21:03:12

if firefox blocks loading extra files that gonna be tricky

thheller21:03:29

I have no clue what firefox exts look like

thheller21:03:36

so I cannot really offer any suggestions

frankitox00:03:59

Yeah, I guess this would be better asked at some Firefox forum

frankitox00:03:31

Still, thank you :D

Matthew Downey00:03:31

I know in Chrome, you'd need to have a "web_accessible_resources" declaration in the manifest for anything else you wanted the main.js file to pull in

frankitox01:03:48

Thanks! That unstuck me 😄 I had to also allow eval (only with v2 manifests), but after that and some changes in :asset-path and :devtools-url in the shadow config, I'm finally getting a "shadow-cljs ready!" message!

🎉 2
skylize13:03:22

Maybe https://babashka.org/scittle/ would be a good choice for a browser extension? Looks like you can https://github.com/babashka/scittle/tree/main/doc/nrepl.

2