fix(query-core): prevent optimistic fetching when unsubscribedFix/subscribed isfetching#10720
fix(query-core): prevent optimistic fetching when unsubscribedFix/subscribed isfetching#10720Prasadzoman wants to merge 2 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR fixes a bug where ChangesOptimistic result behavior for unsubscribed observers
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
Problem
When using the
subscribedoption (common React Native pattern for unfocused screens),isFetchingcould becometrueeven though:queryFnwas not calledThis resulted in an inconsistent state where:
while the query was actually idle.
Fixes #10718.
Root Cause
QueryObserver.createResultoptimistically injectedfetchState(...)whenever:However,
!mountedwas true both for:subscribed: false)This caused optimistic fetching state to appear even after unsubscribing.
Fix
Adds tracking for whether the observer has ever been subscribed via
#everSubscribed.Optimistic fetch state is now only applied for genuine pre-subscription optimistic renders.
Additionally:
updateResultnow accepts an optimistic flaggetOptimisticResultpasses the correct optimistic state#notifyskips cache notifications when no listeners existTests
Added regression coverage for:
isFetchingfetchStatussubscribed: falseAll existing tests pass.
Summary by CodeRabbit
Bug Fixes
fetchStatus: 'idle'andisFetching: falsewhen appropriate.Refactor