This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-09-29
Channels
- # announcements (4)
- # babashka (66)
- # beginners (7)
- # cljs-dev (6)
- # clojure (12)
- # clojure-europe (28)
- # clojure-nl (1)
- # clojure-norway (75)
- # clojure-uk (16)
- # clojuredesign-podcast (1)
- # clojurescript (16)
- # datascript (6)
- # deps-new (2)
- # dev-tooling (40)
- # exercism (1)
- # fulcro (92)
- # hyperfiddle (25)
- # lsp (19)
- # malli (1)
- # meander (2)
- # nrepl (9)
- # off-topic (5)
- # pathom (1)
- # practicalli (1)
- # re-frame (20)
- # reitit (14)
- # releases (1)
- # sci (86)
- # shadow-cljs (216)
- # sql (13)
- # testing (4)
- # tools-deps (4)
- # vscode (3)
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…
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.
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
👀
I’ll ask in #C6N245JGG,thx!
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) $
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/
Yep, the two are the same
Oh, by reproduce
do you mean the :whitespace
issue, which ☝️ does, or the dom not updating issue?
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}}}
:optimizations :none
always worked, at least wrt the goog problem?!
when I print the result of the evalstring in advanced I see:
"<h3>Hello from Fulcro!</h3>"
in the consoleI 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)
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\"))
")
)
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)
Exactly. That is why I bug Thomas, as he is the most knowledgable person 🙂
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\"))
")
)
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…
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
@U0522TWDA 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
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…
The PR is now ready 🙏 I did not manage to make just 2 commits, so it might be best to squash then… 😭
🔨 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
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 ?