Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix OM 862 - Race condition between schedule-render! and send cb's reconcile! that prevents some future reconciling #863

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions src/devcards/om/devcards/bugs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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 increment by 2> should not
prevent <Should increment by 1> from scheduling a
reconcile! Try clicking first on <Should increment by 2> and
then try clicking on <Should increment by 1>.")
(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])
Expand Down
8 changes: 5 additions & 3 deletions src/main/om/next.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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])
#?(:cljs (schedule-render! r)))
(when-not (nil? reads)
(p/queue! r reads))
(p/queue! r reads)
#?(:cljs (schedule-render! r)))
(p/reindex! r)
(let [rootq (if (not (nil? c))
(full-query c)
Expand Down Expand Up @@ -2489,7 +2491,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 []))
Expand Down