Update: It works with shadow :optimizations none but not w/ :simple
Update2: The problem is with my rewrite of defsc macro; if I change Root to Root2 at both occurrences then I get to see the updates.
Update3: FIXED - I had to change a defonce inside the defsc sci macro to def and now I can redefine component classes even in release mode
@borkdude & @tony.kay I need your awesome brains to figure out why https://blog.jakubholy.net/2023/interactive-code-snippets-fulcro/#_demo does not modify the DOM. I see that the script is stateful, but that shouldn’t be a problem? I know the script runs fine (I can add 1, 2 , .. to the bottom to see it change) but when I change the text inside the Root fulcro component (which becomes a JS function), the output (mounted below the editor) does not change. In a normal Fulcro app, the code works fine.
I thought this did work before for me, but I could be mis-remembering…
When I run the https://github.com/holyjak/sci.configs/blob/add-fulcro/README.md#development in sci.configs, the following works, which IMO is essentially the same as the in-blog editor being modified and re-evaluated: 🧵
sci.configs/development.cljs - eval first the one, so the second:
(comment
(sci/eval-string* full-ctx "
(do
(ns test (:require
[com.fulcrologic.fulcro.dom :as dom]
[com.fulcrologic.fulcro.application :as app]
[com.fulcrologic.fulcro.components :as comp :refer [defsc]]))
(defonce app2 (do (println \"Def app!\") (app/fulcro-app)))
(comp/defsc Root [_ _] (dom/div (dom/h3 \"One\")))
(app/mount! app2 Root \"app\"))
")
(sci/eval-string* full-ctx "
(do
(ns test (:require
[com.fulcrologic.fulcro.dom :as dom]
[com.fulcrologic.fulcro.application :as app]
[com.fulcrologic.fulcro.components :as comp :refer [defsc]]))
(defonce app2 (do (println \"Def app!\") (app/fulcro-app)))
(comp/defsc Root [_ _] (dom/div (dom/h3 \"TWO\")))
(app/mount! app2 Root \"app\"))
")
,)So the question is, what is the difference, and how to troubleshoot this? 🙏
Hm, I have a similar dev playground in my blog, and there it works fine as well, changing stuff in the editor and seeing the dom updated. So either it is something with release build of the editor or something else…
could you first figure out if it's a release (advanced) issue?
Yes and no. If I switch from :advanced to :optimizations :simple , I still have the problem. But with no optimizations, i.e. running shadow-cljs watch, it works.
so it's none vs simple/advanced? interesting
Most likely. Trying :whitespace now…
you can try to debug the build with --debug and insert lots of printlns etc. without knowing the code/fulcro, it's hard for me to say
I will look into that, thank you. BTW, how can I make it possible to use js/console.log , js/document etc from SCI?
Hm, :whitespace result fails to load with TypeError: goog is undefined 👀
interesting
perhaps a macro is expanding into something with goog?
normally the goog namespace exists under optimizations none
but this gets compiled away under simple and more
I’ll ask in #shadow-cljs,thx!
one of your macros I mean
it's likely not a shadow issue
hmm, not seeing any goog references here:
borkdude@m1 ~/dev/sci.configs (holyjak-add-fulcro) $ rg "goog"
src/sci/configs/cljs/test.cljs
102: See
borkdude@m1 ~/dev/sci.configs (holyjak-add-fulcro) $ try to require [goog.object] explicitly when you use it from any code
there was a difference in a recent ClojureScript version about this
seems to be ok in fulcro
Fulcro itself uses goog. But it fails at some place that seems unrelated to Fulcro itself to mee https://clojurians.slack.com/archives/C6N245JGG/p1695987235272819?thread_ts=1695987098.691529&cid=C6N245JGG
1. Get latest https://github.com/holyjak/sci.configs/blob/add-fulcro/
2. Run bb dev:release
3. Do cd www; python3 -m http.server 8009
4. Go to http://localhost:8009/
can you maybe push you changes to the PR?
I already have that one locally
oh you already did
Yep, the two are the same
Oh, by reproduce do you mean the :whitespace issue, which ☝️ does, or the dom not updating issue?
I'm seeing the same goog issue here:
goog.provide("goog.events.EventWrapper");
It could be an issue with asset-path
I changed the config to just this:
:builds {:dev {#_#_:compiler-options {:output-feature-set :es8
:optimizations :none #_whitespace}
:target :browser
:output-dir "www/js"
#_#_:asset-path "/js/dev"
:modules {:dev {:init-fn development/init}}
:devtools {:after-load development/reload}}}and <script src="js/dev.js" type="text/javascript"></script>
and now I see at least Init run
and no errors in the console
:optimizations :none always worked, at least wrt the goog problem?!
in release this is advanced
I don't think shadow supports anything else than none or advancd
when I print the result of the evalstring in advanced I see:
"<h3>Hello from Fulcro!</h3>"
in the consoleso things seem to be working if you just get rid of those extra settings
I moved the first sci/eval-string* from the comment form to the init function
I am quite sure that shadow supports at least simple , and most likely whitespace . Both are mentioned in the guide, and simple worked for me (and was clearly bigger than advanced)
thheller just told you that it doesn't :)
😅
To replicate the Fulcro problem:
1. Modify development.cljs to have init as shown below
2. Run bb dev:release
3. Run
4. Access the page. It will show One and not TWO as expected
(defn init []
(println "Init run")
(sci/eval-string* full-ctx "
(do
(ns test (:require
[com.fulcrologic.fulcro.dom :as dom]
[com.fulcrologic.fulcro.application :as app]
[com.fulcrologic.fulcro.components :as comp :refer [defsc]]))
(defonce app2 (do (println \"Def app!\") (app/fulcro-app)))
(comp/defsc Root [_ _] (dom/div (dom/h3 \"One\")))
(app/mount! app2 Root \"app\"))
")
(sci/eval-string* full-ctx "
(do
(ns test (:require
[com.fulcrologic.fulcro.dom :as dom]
[com.fulcrologic.fulcro.application :as app]
[com.fulcrologic.fulcro.components :as comp :refer [defsc]]))
(defonce app2 (do (println \"Def app!\") (app/fulcro-app)))
(comp/defsc Root [_ _] (dom/div (dom/h3 \"TWO\")))
(app/mount! app2 Root \"app\"))
")
)
yes, it shows One here
When I remove the first expression, I see Two
Of course. That is the whole problem: somehow, we can only set the dom once, and never changed it - but only with :optimizations . w/o them it works fine.
Does this have anything to do with it?
Warning: ReactDOM.render is no longer supported in React 18. Use createRoot instead. Until you switch to the new API, your app will behave as if it's running React 17. Learn more: If, by first expression, you mean the first eval-string* call No, the warning can be safely ignored. You get it in both working and broken version (and in my prod app, which too works just fine)
ok, then I suspect there is something going on with advanced compilation
this is not uncommon
Exactly. That is why I bug Thomas, as he is the most knowledgable person 🙂
let's not bug Thomas with this, it's not a bug in shadow-cljs
it's just probably something you emit in a SCI macro that is prone to renaming
like some interop thing
Could be. But how do I find that out? I used --debug but did not see any observable effect.
> But how do I find that out? By debugging stuff, bisecting, splitting problems into sub-problems
I'd try to insert some printlns just before it would (re)mount the component to see what it's doing
perhaps necessary to add a :local/root dependency to fulcro to insert the right stuff at the right place
Guess what, it does start to work when you rename some variables:
(defn init []
(println "Init run")
(sci/eval-string* full-ctx "
(do
(ns test (:require
[com.fulcrologic.fulcro.dom :as dom]
[com.fulcrologic.fulcro.application :as app]
[com.fulcrologic.fulcro.components :as comp :refer [defsc]]))
(defonce app2 (do (println \"Def app!\") (app/fulcro-app)))
(comp/defsc Root [_ _] (dom/div (dom/h3 \"One\")))
(app/mount! app2 Root \"app\"))
")
(sci/eval-string* full-ctx "
(do
(ns test (:require
[com.fulcrologic.fulcro.dom :as dom]
[com.fulcrologic.fulcro.application :as app]
[com.fulcrologic.fulcro.components :as comp :refer [defsc]]))
(defonce app3 (do (println \"Def app!\") (app/fulcro-app)))
(comp/defsc Root2 [_ _] (dom/div (dom/h3 \"TWO\")))
(app/mount! app2 Root2 \"app\"))
")
)renaming the second Root to Root2 seems to be enough
Nice catch! Thank you.
So it seems I can mount a new function, but not change an existing one, with :optimizations . Now to find out why, and how to make it work without renaming…
indeed
so maybe it's an issue with mount! OR it is an issue with defsc (in the SCI config)
ok, to recap: if we change defonce in defsc to def it starts working, but strangely enough it works in dev mode even with the defonce
@holyjak Congrats on your cool article :) Is the PR ready for merge?
Thank you! Pls wait, we are looking into some issues w/ state management with Tony. I will draftify it for now
sure
I was thinking that it might be nice to end up with 2 commits, one which adds fulcro, and one adding the dev support. If you agree then I will clean up history so it is that way. If you want to squash it into one, then I don’t need to do that…
whatever you want
The PR is now ready 🙏 I did not manage to make just 2 commits, so it might be best to squash then… 😭
I always squash PRs
🔨 FTW! 🙂
If you want you could contribute a playground with all libraries which we could deploy via github pages (I already have a good pages setup e.g. for https://github.com/oxalorg/4ever-clojure, so just the html + JS compiled is what I would need) no hurry, might just be cool to test a bit with the existing sci.configs
some other time
merged
Thank you!
> playground with all libraries which we could deploy via github
So essentially something like development.cljs, but with sci prebuilt (in the way I do for my blog), and having a static page with an editor and this sci version, so people could play with it? Essentially invoke sci.configs’ bb dev:release + combine with https://gist.github.com/holyjak/4c7048f2fe385c1ae826c6603fbcb560 ?
yeah indeed
anyway, totally optional
thanks for your PR!
My pleasure! Many thanks for your help! How you imagine ☝️ would work? Just a GH Action on sci.configs that would run bb & push the resulting .js + the one .html to a branch, connected to GH Pages?
@borkdude you don't happen to distribute a libsci prebuilt for various platforms do you?
nope
$ apt install libsci-dev
$ yum install libsci-dev
$ brew install libsci
etc would be really cool. I'm looking for a way to automate that kind of thing.
I need to bistribute libyamlscript like thatbrew is easy. I never burned my hands at apt
Also I think building libyamlscript with sci included is the wrong way to go.
Bindings should bind both libyamlscript and libsci
I do usually include manual bash scripts so people can install binaries locally
probably you should just first focus on those install scripts and only worry about package managers later, if it comes to that
I can see a world where dozens of python modules bind to libsci and that should only be in memory once
python is just a random example lang
if graal builds were not so slow, I could see building it at binding install time
but for major platforms it would be could to have system installs
but yeah, I can do it badly before goodly
I usually wait for people to ask "is thing x in package manager y". Only then you know it's worth putting energy into it. And even then I will usually say: "no, do you want to maintain package x for package manager y? Thank you", as there is only so much you can do in a day
It just seems like there should be a meta builder for all these major platforms
the apt ecosystem is pretty closed, it seemed totally not fun working on that. brew (linux and mac) and scoop (similar thing for Windows) are easy starters
closed and cargo-culted
yeah, it does seem archaic 😞
I wonder for libsci in your project, if you would do the communication via JSON or do the more advanced stuff and support numbers, strings, etc.
My need is a single function to read and eval a clojure form (string) and return a json string (for now)
I did a similar experiment for a library in postgres: https://github.com/borkdude/plsci
I like the Slack badge! Never seen that.
slack badge?
oh yeah I see now
forgot that I had it in there ;)
hahah
I've also seen references to libclojure. Is that (still) a thing?
not sure what that is
well now I can't find a single reference about that
I’ll throw in another plug for building bb such that it can also be a link target. That way everyone who installs bb will also have a libsci available for things like this.