Don't catch exceptions in render

This commit is contained in:
Dan Holmsand 2015-08-30 23:07:34 +02:00
parent ea021d3b87
commit 4ccec97274
1 changed files with 15 additions and 16 deletions

View File

@ -107,24 +107,23 @@
(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
(.! node :innerHTML "")
(catch :default e
(do (warn "Error unmounting:")
(log e)))))
(some-> node
(.! :innerHTML "")))
(defn render-component [comp container callback]
(let [rendered (volatile! nil)]
(try
(binding [*always-update* true]
(.' js/React render (comp) container
(->> (.' js/React render (comp) container
(fn []
(binding [*always-update* false]
(swap! roots assoc container [comp container])
(if (some? callback)
(callback))))))
(catch :default e
(do (clear-container container)
(throw e)))))
(callback)))))
(vreset! rendered)))
(finally
(when-not @rendered
(clear-container container))))))
(defn re-render-component [comp container]
(render-component comp container nil))