From e01b8218d79fdb8ee2ad2017b6266d4a79559591 Mon Sep 17 00:00:00 2001 From: Brian Noguchi Date: Wed, 5 Apr 2017 13:15:30 -0700 Subject: [PATCH 1/4] Add failing devcard test for GH-862 --- src/devcards/om/devcards/bugs.cljs | 52 ++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/devcards/om/devcards/bugs.cljs b/src/devcards/om/devcards/bugs.cljs index daa7f0e5..f70e44fa 100644 --- a/src/devcards/om/devcards/bugs.cljs +++ b/src/devcards/om/devcards/bugs.cljs @@ -1025,6 +1025,58 @@ (dom/create-element "use" #js {:xlinkHref "#rectangle" :x "150"}))) +(def om-862-state (atom {:count 1})) +(def om-862-reconciler + (om/reconciler {:state om-862-state + :remotes [:remote] + :parser (om/parser + {:read (fn [{:keys [state]} key _] + {:value (get @state key)}) + :mutate (fn [{:keys [state]} key _] + {:value {} + :action #(swap! state + update :count inc) + :remote (= 'count/inc-by-each-remote + key)})}) + :send (fn [{:keys [remote]} cb] + (when remote + (let [resp {:count (inc (:count @om-862-state))} + query [:count]] + (cb resp query remote))))})) + +(defui om-862-Root + static om/IQuery + (query [this] + [:count]) + Object + (render [this] + (let [props (om/props this)] + (dom/div nil + (dom/div + nil + "Clicking first on should not + prevent from scheduling a + reconcile! Try clicking first on and + then try clicking on .") + (dom/button + #js {:onClick #(om/transact! + this '[(count/inc-by-each-remote)])} + "Should increment by 2") + (dom/button + #js {:onClick #(om/transact! + this '[(count/inc-only-client)])} + "Should increment by 1") + (dom/div nil (:count props)))))) +; Override om/*raf* to force the race condition that causes the abberant +; om-862 behavior +(set! om/*raf* (fn [f] + (println "*raf* override called") + (f))) +(defcard om-862-card + (dom-node + (fn [_ node] + (om/add-root! om-862-reconciler om-862-Root node)))) + (comment (require '[cljs.pprint :as pprint]) From 2b3e7023b400a423bfb9b69b7f74b71b3030702d Mon Sep 17 00:00:00 2001 From: Brian Noguchi Date: Wed, 5 Apr 2017 13:18:23 -0700 Subject: [PATCH 2/4] GH-862 fix Always set :queued to false in reconcile\! --- src/main/om/next.cljc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/om/next.cljc b/src/main/om/next.cljc index 38396636..d06f4e3d 100644 --- a/src/main/om/next.cljc +++ b/src/main/om/next.cljc @@ -2489,7 +2489,7 @@ q (if-not (nil? remote) (get-in st [:remote-queue remote]) (:queue st))] - (swap! state update-in [:queued] not) + (swap! state assoc :queued false) (if (not (nil? remote)) (swap! state assoc-in [:remote-queue remote] []) (swap! state assoc :queue [])) From 16fa60ffa7028c71753d65cd07ee0bc5986b17c6 Mon Sep 17 00:00:00 2001 From: Brian Noguchi Date: Wed, 5 Apr 2017 16:08:09 -0700 Subject: [PATCH 3/4] Make sure to schedule-render! after queueing components or reads. Otherwise, this doesn't work when merged with om-860 because the devcards for om-860 also exposes a race condition with the overriding om/*raf* we define in this branch. --- src/main/om/next.cljc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/om/next.cljc b/src/main/om/next.cljc index d06f4e3d..943b1e88 100644 --- a/src/main/om/next.cljc +++ b/src/main/om/next.cljc @@ -1314,9 +1314,11 @@ (swap! st update-in [:om.next/queries (or c root)] merge (merge (when query {:query query}) (when params {:params params}))) (when (and (not (nil? c)) (nil? reads)) - (p/queue! r [c])) + (p/queue! r [c]) + (schedule-render! r)) (when-not (nil? reads) - (p/queue! r reads)) + (p/queue! r reads) + (schedule-render! r)) (p/reindex! r) (let [rootq (if (not (nil? c)) (full-query c) From cc9d19f4d1575f6476ccf93eb32109a0e92bb150 Mon Sep 17 00:00:00 2001 From: Brian Noguchi Date: Tue, 8 Aug 2017 09:35:00 -0700 Subject: [PATCH 4/4] Don't call schedule-render! in jvm --- src/main/om/next.cljc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/om/next.cljc b/src/main/om/next.cljc index 943b1e88..f0e8fc54 100644 --- a/src/main/om/next.cljc +++ b/src/main/om/next.cljc @@ -1315,10 +1315,10 @@ (merge (when query {:query query}) (when params {:params params}))) (when (and (not (nil? c)) (nil? reads)) (p/queue! r [c]) - (schedule-render! r)) + #?(:cljs (schedule-render! r))) (when-not (nil? reads) (p/queue! r reads) - (schedule-render! r)) + #?(:cljs (schedule-render! r))) (p/reindex! r) (let [rootq (if (not (nil? c)) (full-query c)