Fork me on GitHub
#shadow-cljs
<
2024-04-05
>
andrea12:04:40

Is there some depth limit to what gets hot-reloaded? I'm still trying to isolate the problem but it looks like my views (using re-frame) do not get reloaded if I make changes in something that's 3 steps removed (as nested :require) from my entry point. Adding an import at top level fixes the issue but it doesn't look right to me. I'm already using :reload-strategy :full

thheller13:04:25

are you setting that in the correct place?

thheller13:04:10

I don't really have much too add to that

thheller13:04:48

:reload-strategy does not affect what gets compiled, so if you are relying on some macro stuff changing that might be the reason?

thheller13:04:43

other than that I can't say more without additional info

Ben Lieberman14:04:06

are you using react 18? in reagent (and thus re-frame) there is this issue https://github.com/reagent-project/reagent/issues/579. I have encountered it a few times myself.

thheller14:04:06

this is not new and has always worked like this, nothing special regarding react 18

thheller14:04:18

thats why the blog post I just linked has a section for that regarding react

thheller14:04:48

(defn ^:dev/after-load start []
  ;; dummy prop that always changes
  (reagent/render [ui {:x (js/Date.now)}] dom-root))

thheller14:04:20

but :reload-strategy :full also adresses this

andrea14:04:45

Thanks both! After some more investigation is not the simple importing I described. If I just renderer the view hot-reload works correctly. The problem is with the way I set up reitit routing, probably wrongly. The routes list contains refs to the views and I render them from the router. I think that becomes stale in some way that I have yet to debug.

guillermo22:04:26

Hello @U47V0EZF1 I am facing exactly the same issue you are describing, and after testing different variants, I found that this way hot-reload works again, very ugly though

(def routes
  ["/" {:name ::home
        :view (fn []
                [home-page])}])
https://github.com/guillerglez88/hl7v2-lab/blob/master/src/hl7v2_lab/core.cljs if you find a solution for this, please, @menction me to be aware.

thheller05:04:42

and that is the correct and only workaround. shadow-cljs cannot update functions you put into a map in some place. creating an extra functions delays the lookup of the actual function until needed, so it always gets the latest hot-reloaded version.

thheller05:04:29

well I shouldn't say it is the only workaround. frankly the routing data should only consist of data, never functions. then in the place that is actually using it use that data

thheller05:04:03

something like

(defn app []
  (let [view (get-in @route-match [:data :view])]
    (case view
      :home [home-page]
      [not-found])))


(def routes
  ["/" {:name ::home
        :view :home}])

guillermo05:04:27

oh, I see! thank you @U05224H0W , I will use a keyword instead of a function as you suggested.

thheller05:04:22

could even just dispatch on the :name, no need for the :view field.

guillermo06:04:57

is it possible to use :view 'home a symbol, will it work?

thheller06:04:45

will what work? its a symbol. yes you can use symbols. if you expect that to magically call the function then no, that will not work.

guillermo06:04:58

thank you for your support @U05224H0W!