fix(query-core): use !== undefined for timer ID checks to handle falsy 0#10402
fix(query-core): use !== undefined for timer ID checks to handle falsy 0#10402ljjunh wants to merge 1 commit intoTanStack:mainfrom
Conversation
📝 WalkthroughWalkthroughThis PR fixes a bug where falsy timer IDs (e.g., Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
.changeset/seven-facts-unite.md (1)
5-6: Changeset description is incomplete.The description only mentions
clearGcTimeout, but the fix also applies to#clearStaleTimeoutand#clearRefetchIntervalinqueryObserver.ts. Consider updating for accurate release notes.📝 Suggested changeset description
-fix: use !== undefined instead of truthy check for timer IDs to correctly handle falsy value 0 in clearGcTimeout, +fix: use !== undefined instead of truthy check for timer IDs to correctly handle falsy value 0 in clearGcTimeout, clearStaleTimeout, and clearRefetchInterval🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In @.changeset/seven-facts-unite.md around lines 5 - 6, Update the changeset description in .changeset/seven-facts-unite.md to accurately reflect that the fix replaces truthy checks with explicit !== undefined checks not only in clearGcTimeout but also in `#clearStaleTimeout` and `#clearRefetchInterval` inside queryObserver.ts; mention all three methods so release notes correctly state that timer IDs with falsy value 0 are now handled properly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In @.changeset/seven-facts-unite.md:
- Around line 5-6: Update the changeset description in
.changeset/seven-facts-unite.md to accurately reflect that the fix replaces
truthy checks with explicit !== undefined checks not only in clearGcTimeout but
also in `#clearStaleTimeout` and `#clearRefetchInterval` inside queryObserver.ts;
mention all three methods so release notes correctly state that timer IDs with
falsy value 0 are now handled properly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 87fe1f68-ef84-4589-817e-46877d8104b1
📒 Files selected for processing (5)
.changeset/seven-facts-unite.mdpackages/query-core/src/__tests__/queryObserver.test.tsxpackages/query-core/src/__tests__/removable.test.tsxpackages/query-core/src/queryObserver.tspackages/query-core/src/removable.ts
🎯 Changes
Fixes #10395
Timer IDs can legally be
0when using a custom timeout provider. The current code uses truthy checks (if (this.#gcTimeout)) before callingclearTimeout/clearInterval, which silently skips cleanup when the ID is0since0is falsy in JavaScript.Three locations were affected:
removable.tsclearGcTimeout()#gcTimeoutqueryObserver.ts#clearStaleTimeout()#staleTimeoutIdqueryObserver.ts#clearRefetchInterval()#refetchIntervalIdReplace truthy checks with explicit
!== undefinedcomparisons: