Fork me on GitHub
#shadow-cljs
<
2024-07-11
>
Pavel Klavík20:07:36

Hi, I have a Node-js application for which code does not reload correctly. Here is config:

:screenshot {:target           :node-script
                             :main             orgpad.screenshot.core/main
                             :output-to        "screenshot/screenshot.js"
                             :devtools         {:autoload true}
                             :compiler-options {:optimizations :simple}}
I run shadow-cljs watch screenshot, it compiles. Then I run node screenshot. When I do a change, shadow-cljs watch detects it and recompiles screenshot. But the change is not available in running node screenshot, only after killing it and starting again. For example, I introduce a new function orgpad.server.core/test. I get the following in shadow-cljs watch output:
[:screenshot] Compiling ...
[:screenshot] Build completed. (221 files, 1 compiled, 7 warnings, 0.29s)
Nothing is in node screenshot output, it should contain shadow-cljs - #N ready I think.

Pavel Klavík20:07:17

There might be some problems with our self-signed certificates. But the same build for our JS client correctly reloads. So I am not sure whether it is related at all.

thheller20:07:12

kinda impossible to answer since I do not know what the app does. hot reload always works the same. the process connects back to shadow-cljs, gets infos about builds, and triggers a reload when a build completes

thheller20:07:18

so it may fail to connect back to shadow-cljs

thheller20:07:42

maybe you don't have a :dev/after-load hook set?

thheller20:07:43

node is also known for keeping state in function closures, which cannot be hot reloaded

Pavel Klavík22:07:58

I have added :after-load into :devtools, as a simple function which logs something to the console. And now the files are correctly reloaded. For example adding some function allows me to run it in REPL. So when this hook is missing, Shadow-cljs does nothing with updated code?

thheller07:07:40

it should still be reloading all code normally. the after-load function is just normally the thing that "realizes" the changes. e.g. in the client re-renders the UI, or in node restarts something

Pavel Klavík09:07:00

I have found this in documentation yesterday: "If neither :after-load nor :before-load are set the compiler will only attempt to hot reload the code in the :browser target. If you still want hot reloading but don’t need any of the callbacks you can set :autoload true instead." But autoload was set before. What happened before that I added a new function in a namespace, and it was not accessible in REPL. After adding :after-load, it is now correctly accessible. Not sure what was happening.

thheller10:07:34

:autoload true is the default, so it doesn't do anything setting it