From ed947f12d1557e0ecd799064c48200745bdd2e94 Mon Sep 17 00:00:00 2001 From: okxint Date: Fri, 20 Nov 2026 07:32:54 -0800 Subject: [PATCH] fix(hydration): use Symbol sentinel in tryResolveSync to handle undefined resolution Using undefined as the sentinel for 'not yet resolved' meant a promise that synchronously resolved with undefined was indistinguishable from one that hadn't resolved. The function returned undefined instead of { data: undefined }, causing the caller to spin up a redundant async retryer for queries that already had their data. --- packages/query-core/src/hydration.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/query-core/src/hydration.ts b/packages/query-core/src/hydration.ts index 1eea8c90748..4b343634f0d 100644 --- a/packages/query-core/src/hydration.ts +++ b/packages/query-core/src/hydration.ts @@ -21,10 +21,12 @@ type TransformerFn = (data: any) => any * resolves within its `then` call. * @param promise - The promise to read. * @returns An object with the resolved `data`, or `undefined` if the promise hasn't resolved - * synchronously (or resolved with `undefined`). + * synchronously. */ +const UNRESOLVED = Symbol('unresolved') + function tryResolveSync(promise: PromiseLike) { - let data: unknown + let data: unknown = UNRESOLVED const thenResult = promise.then((result) => { data = result @@ -35,7 +37,7 @@ function tryResolveSync(promise: PromiseLike) { // oxlint-disable-next-line typescript/no-unnecessary-condition thenResult?.catch?.(noop) - if (data !== undefined) { + if (data !== UNRESOLVED) { return { data } }