-
Notifications
You must be signed in to change notification settings - Fork 412
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
React 18 does not live reload with Shadow-CLJS in non-trivial projects #579
Comments
hey @filipesilva does your project work fine with React18? any issues except live reloading? thanks |
@flexsurfer we had some trouble with other third party js lib and ended up going back to 17. It seemed like reagent was fine with it though. |
hey @Deraen , tested latest master , hot reload works fine, any chance we could have a snapshot or release on clojars? thanks |
I've been testing my library with React 18, and tried the new Both of @filipesilva's workarounds appear to partially mitigate the issue. But I'm not exactly sure that it is specific to React 18. When using Interestingly, if I revert commit 9211080 on the |
Wrapping the call to (binding [util/*always-update* true]
(react-dom/render
(react/createElement reagent-root #js {:callback callback
:comp comp})
container)) But I still can't get the new |
There are still a lot of gotchas with Reagent + React 18. Specifically, see: reagent-project/reagent#579 Without the workaround described in that issue, root React nodes, like the debugger overlay don't hot reload properly.
There are still a lot of gotchas with Reagent + React 18. Specifically, see: reagent-project/reagent#579 Without the workaround described in that issue, root React nodes, like the debugger overlay don't hot reload properly.
There are still a lot of gotchas with Reagent + React 18. Specifically, see: reagent-project/reagent#579 Without the workaround described in that issue, root React nodes, like the debugger overlay don't hot reload properly.
There are still a lot of gotchas with Reagent + React 18. Specifically, see: reagent-project/reagent#579 Without the workaround described in that issue, root React nodes, like the debugger overlay don't hot reload properly.
There are still a lot of gotchas with Reagent + React 18. Specifically, see: reagent-project/reagent#579 Without the workaround described in that issue, root React nodes, like the debugger overlay don't hot reload properly.
This report is before 1.2.0 release so I hope this works with the new |
Using Reagent+React18+Shadow-CLJS will not live reload unless if the file changed is a direct dependency of the file containing the render code.
I have a repro that illustrates this behaviour:
Open http://localhost:3001 in your browser and you should see the following:
The browser console will show the following:
Each component is on a different file,
app.core/main
will rendercomp1
,comp1
will rendercomp2
, andcomp2
will rendercomp3
. Each comp will print to the console when rendered. Arender
fn has the^:dev/after-load
metadata that causes Shadow-CLJS to call it after code changes.If you edit
comp1
orcomp2
(e.g. add another number to the string), live reload will work. If you editcomp3
, it will not.As far as I can tell, the core reason is that the new React 18 rendering fn keeps some state, and will not render the root element unless it changed. In React <17, I think it always rerendered when
.render
was called.Specific to Shadow-CLJS is that it will reload the changed file and all files that directly depend on it, then call the
after-load
fn. You can see logs for this in the console when changingcomp3
:Note that the
render compX
logs never appeared. In contrast, when editingcomp2
:So far I've found two workarounds for this:
(.render root (r/as-element [(fn [] comp1/main)]))
^:dev/always
, which causes it to always be reloaded when any file changes.Unsure if there's any better ways.
The text was updated successfully, but these errors were encountered: