From de1961c0d21aacb193e80b3faf7e76f5251b9e44 Mon Sep 17 00:00:00 2001 From: TkDodo Date: Mon, 23 Mar 2026 13:59:41 +0100 Subject: [PATCH 1/2] fix(timeout): make sure NodeJs.Timout doesn't leak --- packages/query-core/src/timeoutManager.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/query-core/src/timeoutManager.ts b/packages/query-core/src/timeoutManager.ts index 97f0870eea2..6f74050b04c 100644 --- a/packages/query-core/src/timeoutManager.ts +++ b/packages/query-core/src/timeoutManager.ts @@ -28,9 +28,9 @@ export type TimeoutProvider = readonly clearInterval: (intervalId: TTimerId | undefined) => void } -export const defaultTimeoutProvider: TimeoutProvider< - ReturnType -> = { +type SystemTimerId = ReturnType + +export const defaultTimeoutProvider: TimeoutProvider = { // We need the wrapper function syntax below instead of direct references to // global setTimeout etc. // @@ -42,10 +42,12 @@ export const defaultTimeoutProvider: TimeoutProvider< // have a hard reference to the original implementation at the time when this // file was imported. setTimeout: (callback, delay) => setTimeout(callback, delay), - clearTimeout: (timeoutId) => clearTimeout(timeoutId), + clearTimeout: (timeoutId) => + clearTimeout(timeoutId as SystemTimerId | undefined), setInterval: (callback, delay) => setInterval(callback, delay), - clearInterval: (intervalId) => clearInterval(intervalId), + clearInterval: (intervalId) => + clearInterval(intervalId as SystemTimerId | undefined), } /** @@ -62,7 +64,8 @@ export const defaultTimeoutProvider: TimeoutProvider< export class TimeoutManager implements Omit { // We cannot have TimeoutManager as we must instantiate it with a concrete // type at app boot; and if we leave that type, then any new timer provider - // would need to support ReturnType, which is infeasible. + // would need to support the default provider's concrete timer ID, which is + // infeasible across environments. // // We settle for type safety for the TimeoutProvider type, and accept that // this class is unsafe internally to allow for extension. From fd00b500e748c4a6965a41a3990546099e67f0f5 Mon Sep 17 00:00:00 2001 From: TkDodo Date: Mon, 23 Mar 2026 14:00:28 +0100 Subject: [PATCH 2/2] changeset --- .changeset/funny-views-build.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/funny-views-build.md diff --git a/.changeset/funny-views-build.md b/.changeset/funny-views-build.md new file mode 100644 index 00000000000..524b36bfe36 --- /dev/null +++ b/.changeset/funny-views-build.md @@ -0,0 +1,5 @@ +--- +'@tanstack/query-core': patch +--- + +fix(timeoutManager): make sure NodeJs.Timout doesn't leak