fix(query-core): clear timers when timer ID is 0#10401
fix(query-core): clear timers when timer ID is 0#10401semimikoh wants to merge 2 commits intoTanStack:mainfrom
Conversation
Custom TimeoutProvider implementations may return 0 as a valid timer ID (e.g. a counter-based provider), but the existing truthy checks treated 0 as "no timer" and skipped clearTimeout/clearInterval. This left stale timers running, causing unexpected refetches and GC leaks. Compare against undefined instead, matching the optional `?: ManagedTimerId` field types. Fixes TanStack#10395
|
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 (3)
📝 WalkthroughWalkthroughThis PR fixes timer cleanup logic in TanStack Query Core by replacing falsy truthiness checks with explicit Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 |
Custom TimeoutProvider implementations may return 0 as a valid timer
ID (e.g. a counter-based provider), but the existing truthy checks
treated 0 as "no timer" and skipped clearTimeout/clearInterval. This
left stale timers running, causing unexpected refetches and GC leaks.
Compare against undefined instead, matching the optional
?: ManagedTimerIdfield types.Fixes #10395
🎯 Changes
Replace truthy checks on
ManagedTimerIdfields with explicit!== undefinedcomparisons so that a timer ID of
0(legal for customTimeoutProviders) is stillcleared:
packages/query-core/src/removable.ts—clearGcTimeout(#gcTimeout)packages/query-core/src/queryObserver.ts—#clearStaleTimeout(
#staleTimeoutId)packages/query-core/src/queryObserver.ts—#clearRefetchInterval(
#refetchIntervalId)The fields are typed
?: ManagedTimerId, soundefinedis the correct sentinel for"no timer".
✅ Checklist
guide.
pnpm run test:pr.🚀 Release Impact
ithub.com/changesets/changesets/blob/main/docs/adding-a-changeset.md).
Summary by CodeRabbit
Bug Fixes
TimeoutProviders that return0as a valid timer ID. Timers are now correctly cleared when using custom timeout providers that may return falsy timer IDs.