hyperfiddle/electric

Duplicate DOM elements appear during hot reload

den1k opened this issue · 6 comments

den1k commented

video: https://share.cleanshot.com/wkr5K4

(p/defn App []
  (p/server
    (binding [db (p/watch db/conn)]
      (p/client
        (dom/div
          (dom/h1 (dom/text "Create User"))
          (let [{handle-value ::ui/value}
                (ui/input {::dom/type        :text
                           ::dom/placeholder "handle"})

                {email-value ::ui/value}
                (ui/input {::dom/type        :text
                           ::dom/placeholder "email"})]
            (ui/button {::ui/click-event  
                        (p/fn [_]
                              (p/server
                                (println
                                  (db/create-user handle-value
                                                  email-value))))}
                       (dom/text "create user"))))))))

(def ^:export
  main
  #?(:cljs
     (p/boot
       (try
         (binding [dom/node (dom/by-id "root")]
           (App.))
         (catch Pending _)
         (catch Cancelled _)))))

#?(:clj
   (user/browser-main! `main))
den1k commented

this did the trick

(def ^:export
  main
  #?(:cljs
     (p/boot
       (try
         (binding [dom/node (dom/by-id "root")]
           (when (= "dev" (env/get :env))
             (j/call (dom/by-id "root") :replaceChildren)) ; <----
           (App.))
         (catch Pending _)
         (catch Cancelled _)))))

We think this is a hung reactor (stuck during graceful shutdown) and also a second reactor starts; so the app is running twice and the old app is hung. Internal ticket is "app can hang during shutdown (switching entrypoint or hot code reloading) due to network shutting down too soon"

Committed workaround: 4fb652e

Todo: workaround needs to be added to all public repos (photon-starter-app, the replit demos, the two database browsers, etc)

den1k commented

this seems to be fixed, closing