reitit

Chase 2024-05-22T14:03:19.574949Z

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.

juhoteperi 2024-05-22T14:08:38.855159Z

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.

Chase 2024-05-22T15:30:52.477289Z

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

juhoteperi 2024-05-23T07:17:14.485119Z

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.

juhoteperi 2024-05-23T07:18:16.322299Z

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.

juhoteperi 2024-05-23T07:20:33.534199Z

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

juhoteperi 2024-05-23T07:21:11.497269Z

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

juhoteperi 2024-05-23T07:25:34.845969Z

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