Fork me on GitHub
#reagent
<
2023-02-17
>
Omar20:02:06

I updated reagent to 1.2.0 last night with react 18.2.0. How are you guys handling reloading? When I update a component in another namespace that is NOT part of my requires in the namespace that createRoot calls, the namespace requiring it does not update. It will when calling unmount on root. but this causes a flicker. Can test this with something like this:

;; in parent-ns, this is required from layout's ns
(defn parent-comp []
[:div ...
  [child-ns/other-ns]])

;; in child-ns, required from parent's NS, but NOT layout's ns
(defn other-ns []
  [:div "change me"])
Reload code in core.cljs
(defonce *root (atom nil))
(defn ^:dev/after-load mount-components []
  (rf/clear-subscription-cache!)

  ;; Flickers, but works.
  (let [_ (when @*root (.unmount @*root))
        root (reset! *root (rdc/create-root (.getElementById js/document "app")))]
    (rdc/render root [layout/page]))

  ;; When requiring a component from another namespace and updating said component, does not update, UNLESS namespace is included in the layout namespace
  (let [root (or @*root (reset! *root (rdc/create-root (.getElementById js/document "app"))))]
    (rdc/render root [layout/page]))

  ;; Reverts to old react 17, works fine without flickering.
  (rdom/render [layout/page] (.getElementById js/document "app")))

p-himik20:02:23

Have you tried the same with React 17? Reagent doesn't yet support React 18.

Omar20:02:09

Yes, that's my last example in my last code snippet. Reagent 1.2.0 has been updated for react 18 as far as the changelog suggest and most my app works fine with it.

p-himik20:02:51

> Experimental React 18 support IIRC there were some mentions of still existing problems with it somewhere in the issues. In any case, I use 17 with 1.2.0 without manual unmounting and I experience 0 problems - no flickering, no issues with code reloading.

Omar21:02:55

yea me either, I have no downsides to using the older render method. I can just spit out react 18 on my prod build. Not like it matters much, just like to keep things updated 😉