Skip to content

Commit 2bfb12c

Browse files
semimikohTkDodo
andauthored
fix(query-core): clear timers when timer ID is 0 (TanStack#10401)
* fix(query-core): use explicit undefined check for timer IDs 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 * chore: add changeset for TanStack#10395 --------- Co-authored-by: Dominik Dorfmeister 🔮 <office@dorfmeister.cc>
1 parent 48c3975 commit 2bfb12c

3 files changed

Lines changed: 8 additions & 3 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tanstack/query-core': patch
3+
---
4+
5+
fix(query-core): use explicit `undefined` check for timer IDs so that custom `TimeoutProvider`s returning `0` as a valid timer ID are properly cleared

packages/query-core/src/queryObserver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,14 +417,14 @@ export class QueryObserver<
417417
}
418418

419419
#clearStaleTimeout(): void {
420-
if (this.#staleTimeoutId) {
420+
if (this.#staleTimeoutId !== undefined) {
421421
timeoutManager.clearTimeout(this.#staleTimeoutId)
422422
this.#staleTimeoutId = undefined
423423
}
424424
}
425425

426426
#clearRefetchInterval(): void {
427-
if (this.#refetchIntervalId) {
427+
if (this.#refetchIntervalId !== undefined) {
428428
timeoutManager.clearInterval(this.#refetchIntervalId)
429429
this.#refetchIntervalId = undefined
430430
}

packages/query-core/src/removable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export abstract class Removable {
3030
}
3131

3232
protected clearGcTimeout() {
33-
if (this.#gcTimeout) {
33+
if (this.#gcTimeout !== undefined) {
3434
timeoutManager.clearTimeout(this.#gcTimeout)
3535
this.#gcTimeout = undefined
3636
}

0 commit comments

Comments
 (0)