Skip to content

Commit b7ca88a

Browse files
committed
Fix render ratom watches being lost for class components with StrictMode
Same as #640
1 parent 6f645cf commit b7ca88a

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/reagent/impl/component.cljs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,25 @@
193193

194194
:componentDidMount
195195
(fn componentDidMount []
196-
(this-as c (.call f c c)))
196+
(this-as c
197+
(when (.-cleanup-queued ^clj c)
198+
(set! (.-cleanup-cancelled ^clj c) true)
199+
(set! (.-cleanup-queued ^clj c) false))
200+
(when-not (nil? f)
201+
(.call f c c))))
197202

198203
:componentWillUnmount
199204
(fn componentWillUnmount []
200205
(this-as c
201-
(some-> (gobj/get c "cljsRatom") ratom/dispose!)
202-
(batch/mark-rendered c)
206+
;; (some-> (gobj/get c "cljsRatom") ratom/dispose!)
207+
(set! (.-cleanup-cancelled ^clj c) false)
208+
(set! (.-cleanup-queued ^clj c) true)
209+
(.then (.resolve js/Promise nil)
210+
(fn []
211+
(when (false? (.-cleanup-cancelled ^clj c))
212+
(set! (.-cleanup-queued ^clj c) false)
213+
(batch/mark-rendered c)
214+
(some-> (gobj/get c "cljsRatom") ratom/dispose!))))
203215
(when-not (nil? f)
204216
(.call f c c))))
205217

@@ -218,6 +230,7 @@
218230
;; Though the value is nil here, the wrapper function will be
219231
;; added to class to manage Reagent ratom lifecycle.
220232
(def obligatory {:shouldComponentUpdate nil
233+
:componentDidMount nil
221234
:componentWillUnmount nil})
222235

223236
(def dash-to-method-name (util/memoize-1 util/dash-to-method-name))

0 commit comments

Comments
 (0)