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 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.