fix(query-core): notify sibling observers when one unsubscribes during dispatch - #11231
fix(query-core): notify sibling observers when one unsubscribes during dispatch#11231contactjawad wants to merge 1 commit into
Conversation
…g dispatch Query.#dispatch iterated the live observers array while onQueryUpdate() could synchronously splice it (via removeObserver). When one observer unsubscribed a same-query sibling during notification, forEach skipped the next observer, leaving a still-subscribed observer with a stale `pending` result after the query had resolved. Iterate over a snapshot of the observers instead.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe query dispatch loop now iterates over an observer snapshot. A regression test covers observer unsubscription during dispatch, and a patch changeset documents the fix. ChangesQuery observer dispatch
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to The change prevents a sibling observer from being skipped when another observer unsubscribes during notification, with a focused regression test covering the resolved result. No actionable merge-blocking risk remains beyond normal checks and review. Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Query.#dispatchcan skip a still-subscribed observer when another observer on the same query unsubscribes during notification, leaving it with a stalependingresult after the query has already resolved.Root cause
removeObservermutates the observer array in place (this.observers.splice(index, 1)).#dispatchiterates that same live array withthis.observers.forEach(...)and callsonQueryUpdate()synchronously inside the opennotifyManagerbatch. If a listener unsubscribes a same-query observer during that loop, an element is spliced out mid-iteration andforEachskips the next observer.Fix
Iterate over a snapshot (
[...this.observers]) so an observer unsubscribing during notification can't cause a sibling to be skipped.Test
Added a regression test in
queryObserver.test.tsx: two observers subscribe to the same query; observer A unsubscribes itself when it first seessuccess, and the test asserts observer B still receives the resolvedsuccessdata. It fails onmain(expected 'pending' to be 'success') and passes with this change. A changeset is included.Summary by CodeRabbit
Bug Fixes
Tests