Fork me on GitHub
#reitit
<
2024-05-22
>
Chase14:05:19

If anyone ever loses hot reloading capability with shadow-cljs, reagent components, and reitit-frontend here is a great, small article that explains what is happening and how to fix it: https://blog.valerauko.net/2022/12/03/hot-reloading-and-reitit-in-the-frontend/ I was banging my head against the wall for days thinking I had messed up my config or something before finally searching for this on a hunch. Unfortunately the reitit-frontend re-frame example uses figwheel instead so maybe it doesn't need this var component approach.

juhoteperi14:05:38

Vars probably would make sense in the examples. It is better to store the references to the component fns instead of the fn value in app-db/atom. The examples probably work because all code is in one file, so every change will trigger init-routes! call and refresh the function values stored in the re-frame db. Should work even with shadow-cljs in similar case.

Chase15:05:52

Ahh, interesting. Can you explain more why the ‘init-routes!’ call will be triggered on every change just because it’s in one file. So if I change my ‘routes’ in ‘router.cljs’ file, should that be reflected immediately even though it’s in a separate file and therefore ‘init-routes!’ is not called? Sorry if that’s confusing

juhoteperi07:05:14

Depends on if your routes are defined as var... and where they are used. But if you'd store the routing match with component fn value to atom or app-db, you would need to rerun the match logic to refresh the stored value.

juhoteperi07:05:16

Figwheel and Shadow-cljs can have diffrerences on reloading dependences namespaces, AFAIK. If you have ns a and b, and a depends on b. It can matter if a is also reloaded with you change b.

juhoteperi07:05:33

That also changes it so that if you change a, also b is reloaded even if only a was changed.

juhoteperi07:05:11

But with the regular option, changing b, should also cause a recompilation and reload because compiler needs to recompile files when their dependencies change.

juhoteperi07:05:34

If you use after-load hook to run your app init code with routes initialization, it should always call the init routes.