Uh oh!
There was an error while loading. Please reload this page.
fix(query-core): Keep observer notifications stable - #11234
Conversation
Removing an observer in place can shift the active notification loop and skip the next observer. Iterate over a shallow copy so synchronous unsubscriptions keep the old behavior without giving up the faster removal path from TanStack#11214. Co-Authored-By: Codex <noreply@openai.com>
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 path now snapshots observers before notification. A regression test verifies that remaining observers receive updated data after one observer unsubscribes synchronously. A patch changeset documents the fix. ChangesObserver notification stability
Merge Risk:⚪ Minimal · up to This localized change stabilizes observer notifications while preserving the existing removal performance improvement, and no actionable merge-blocking risk remains after normal checks and review. Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 |
View your CI Pipeline Execution ↗ for commit 131504a
☁️ Nx Cloud last updated this comment at |
Uh oh!
There was an error while loading. Please reload this page.
PR #11214 changed observer removal from
filter()tosplice(). That made removing lots of observers much faster, but it also allowed an observer to change the same array while a query was notifying it. If an observer unsubscribed synchronously, the next observer could be skipped and left with stale data.This notifies a shallow copy of the observer array. The removal path still uses
splice(), so the performance improvement from #11214 stays.I ran a local Vitest benchmark that calls
setQueryDataon one query with all observers subscribed:There isn't a meaningful change in notification time. The key change and unmount paths measured in #11214 are unchanged because this does not change observer removal.
Summary by CodeRabbit
Bug Fixes
Tests
Release
@tanstack/query-core.