mirror of https://github.com/status-im/reagent.git
Stop trying to be too clever in render
There's no reliable way of making React forget a mounted tree completely, and the old solution sometimes makes things worse.
This commit is contained in:
parent
cdea2257f2
commit
04325c2e0e
|
@ -17,28 +17,14 @@
|
|||
(swap! roots dissoc container)
|
||||
(.' react-dom unmountComponentAtNode container))
|
||||
|
||||
(defn- clear-container [node]
|
||||
;; If render throws, React may get confused, and throw on
|
||||
;; unmount as well, so try to force React to start over.
|
||||
(try (unmount-comp node)
|
||||
(catch :default e))
|
||||
(some-> node
|
||||
(.! :innerHTML "")))
|
||||
|
||||
(defn- render-comp [comp container callback]
|
||||
(let [rendered (volatile! nil)]
|
||||
(try
|
||||
(binding [util/*always-update* true]
|
||||
(->> (.' react-dom render (comp) container
|
||||
(fn []
|
||||
(binding [util/*always-update* false]
|
||||
(swap! roots assoc container [comp container])
|
||||
(if (some? callback)
|
||||
(callback)))))
|
||||
(vreset! rendered)))
|
||||
(finally
|
||||
(when-not @rendered
|
||||
(clear-container container))))))
|
||||
(binding [util/*always-update* true]
|
||||
(->> (.' react-dom render (comp) container
|
||||
(fn []
|
||||
(binding [util/*always-update* false]
|
||||
(swap! roots assoc container [comp container])
|
||||
(if (some? callback)
|
||||
(callback))))))))
|
||||
|
||||
(defn- re-render-component [comp container]
|
||||
(render-comp comp container nil))
|
||||
|
|
Loading…
Reference in New Issue