diff --git a/.changeset/fix-timer-id-zero-falsy-check.md b/.changeset/fix-timer-id-zero-falsy-check.md new file mode 100644 index 00000000000..7bec3cdab1c --- /dev/null +++ b/.changeset/fix-timer-id-zero-falsy-check.md @@ -0,0 +1,5 @@ +--- +'@tanstack/query-core': patch +--- + +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 diff --git a/packages/query-core/src/queryObserver.ts b/packages/query-core/src/queryObserver.ts index a290c700b58..fa950bcfff3 100644 --- a/packages/query-core/src/queryObserver.ts +++ b/packages/query-core/src/queryObserver.ts @@ -417,14 +417,14 @@ export class QueryObserver< } #clearStaleTimeout(): void { - if (this.#staleTimeoutId) { + if (this.#staleTimeoutId !== undefined) { timeoutManager.clearTimeout(this.#staleTimeoutId) this.#staleTimeoutId = undefined } } #clearRefetchInterval(): void { - if (this.#refetchIntervalId) { + if (this.#refetchIntervalId !== undefined) { timeoutManager.clearInterval(this.#refetchIntervalId) this.#refetchIntervalId = undefined } diff --git a/packages/query-core/src/removable.ts b/packages/query-core/src/removable.ts index 68545f74383..62e524219ca 100644 --- a/packages/query-core/src/removable.ts +++ b/packages/query-core/src/removable.ts @@ -30,7 +30,7 @@ export abstract class Removable { } protected clearGcTimeout() { - if (this.#gcTimeout) { + if (this.#gcTimeout !== undefined) { timeoutManager.clearTimeout(this.#gcTimeout) this.#gcTimeout = undefined }