Skip to content

Commit 8625df7

Browse files
committed
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 #10395
1 parent eac62b8 commit 8625df7

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

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)