Conversation
For queries without cached data, queryFn executes synchronously inside the subscription effect (onSubscribe -> shouldFetchOnMount -> fetch). Any reactive state read by queryFn before its first await was therefore recorded as a dependency of that effect: writes to the state tore the observer down (cancelling the in-flight fetch) and re-subscribed, starting a new fetch from a still-dataless query — indefinitely. Keep the observer read tracked so changing options still re-subscribes, but run the subscription itself inside untrack().
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (5)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe Svelte Query subscription effects now execute observer subscriptions inside ChangesSvelte Query subscription fix
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix · Severity of issue fixed: Medium Suggested reviewers: Merge Risk: ⚪ Minimal · up to The subscription change preserves query reactivity and cleanup while preventing reactive query-function reads from causing refetch loops. No actionable merge-blocking risk remains. 🚥 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 |
Fixes #11541
🎯 Changes
For queries without cached data,
queryFnexecutes synchronously inside the subscription$effect(onSubscribe→shouldFetchOnMount→fetch). Any reactive state read byqueryFnbefore its firstawaitwas therefore recorded as a dependency of that effect. Writes to that state tore the observer down (cancelling the in-flight fetch) and re-subscribed — and since the query stays dataless, every re-subscription starts a new fetch: an unbounded teardown/refetch loop. See #11541 for the full mechanism and the exact set of conditions that sustain it.The fix keeps the
observerread tracked, but runs the subscription itself insideuntrack():Note: the naive
untrack(() => observer.subscribe(...))is not enough — it also untracks theobserverread, so changing queries would no longer re-subscribe. The existing test “should track queries added to an initially empty array” catches that case, which is why the observer read stays outside theuntrack().Applied to both
createBaseQuery.svelte.ts(also coverscreateInfiniteQuery) andcreateQueries.svelte.ts.✅ Checklist
pnpm run test:pr, or these tests do not apply to this pull request.🚀 Release Impact
Summary by CodeRabbit
Bug Fixes
Tests