Repository navigation
fix(tanstack-query): keep queries after useSuspenseQueries suspended - #1390
Merged
Merged
Conversation
useSuspenseQueries retained its suspense promise under a key made of the queries still pending. Once the group settled that key became `[]`, the memo dropped the settled promise, and the hook stopped calling use() on the replay. use() is positional, so a following useSuspenseQuery or useSuspenseQueries in the same component landed on the group's fulfilled position, did not suspend, and rendered with `data` undefined, throwing into the error boundary. Key the group's retained promise by every suspense query it reads, as useBaseQuery already keys by its query hash. Add grouped-to-singular and grouped-to-grouped conformance regressions next to the singular control, a grouped transition hold that rejects a group-wide constant key, and a React differential control for all three orders. Closes #1381 Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm
marked this pull request as ready for review
September 29, 2026 12:30
This was referenced Sep 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #1381.
A component that reads a group with
useSuspenseQueries()and then another suspense query could render the second query'sdataasundefinedwhile that query was still pending. With a string read such asb.data.toUpperCase(), the render threw into@catch, and the error stayed after both queries resolved.Owner: the binding, not core. Octane's
use()is positional and, on a resume replay, keeps the thenable already stored at an occupied position. React 19.2.7'strackUsedThenabledoes the same: it looks thenables up by index and reuses the previous one. So a hook whoseuse()disappears between a suspended attempt and its replay shifts every lateruse()in React too.@tanstack/react-querynever hits this because it throws promises, which have no position. Core stays as is.Root cause.
useSuspensePromise(ininternal.ts) exists to keep reading the promise that suspended a hook call site after it settles, which reserves that call site'suse()position for the replay.useQuerieskeyed that retention by the queries still pending. Once the group settled, the key became[], theuseMemodropped the settled promise, and the group skipped itsuse(). The following query'suse()then replayed the group's fulfilled promise and fell through with pending data.Fix.
useQueriesnow keys the retained promise by every suspense query's hash, so settling no longer changes the key.useBaseQueryalready keys byqueryHash, which is stable through settling, so it needed no change. #943's key-specific retention is preserved: a held transition still restores the committed group's promise. The key contract is now documented onuseSuspensePromise.I considered always calling
use()with a module-level settled thenable when nothing is retained, and did not do it. The same-thenable replay path already covers this bug. A sentinel would not help a call site that becomes pending mid-replay, because the stored thenable at that position still wins. It would also trigger the dev "uncached promise" warning when a position's thenable switches, and add one hydration seed per suspense hook to SSR output.Validation
pnpm format:checkpnpm typecheckpnpm test: not run in full. I ran the tanstack-query projects and every package that depends on@octanejs/tanstack-query, listed below.pnpm vitest run --project tanstack-query --project tanstack-query-differential --project tanstack-query-ssr --project tanstack-query-adapted --project tanstack-query-adapted-ssr --project tanstack-query-pristine: 456/456 passed.tanstack-queryconformance suite compiled withoctane({ hmr: false })(scratch config): 44/44 passed.wagmi,wagmi-differential,rainbowkit,rainbowkit-differential,rainbowkit-ssr,solana-kit,solana-kit-adapted,solana-kit-pristine,tanstack-router-ssr-query,tanstack-router-ssr-query-differential,tanstack-router-ssr-query-parity-audit): 153/153 passed.pnpm react-parity:validatepasses; the manifest now lists the new cases and updated hashes.EVIDENCE_PROD=1runs, 6/6 each. Before the fix it failed the two grouped Octane cases in both modes.hmr: falsecompilation, and pass after it:followups.test.ts): the grouped→singular and grouped→grouped cases fail; the singular→singular control passes both before and after.@tanstack/[email protected]and React 19.2.7, run in development compilation: grouped→singular and grouped→grouped diverge at the "first settled, second pending" step. Octane rendersTypeError: …reading 'toUpperCase'where React rendersloading. The singular→singular control matches. With the fix, all 6 differential cases pass, and passed 3 repeated runs.transition-suspense.test.ts): passes before and after, because it guards fix: address React behavioral audit defects #943's behavior rather than this bug. A plausible wrong fix, a group-wide constant key, fixes the sequential cases but fails this test by showing the fallback during the held transition.pnpm typecheck:fileson the changed files reports the same errors before and after, all already present on main infollowups.tsrx(client: unknownprops andElement/ReactNodeunder the React-JSX program). This PR adds none.Risk / follow-ups
useQueries/useSuspenseQueries. Non-suspenseuseQueriesgets a constant"[]"key and never retains a promise.use()whose condition flips when data settles, so a followinguse()in the same component can take its position. None of them uses this retained-promise helper; tanstack-db already callsuse()unconditionally with a settled thenable. These cases were found by reading the code; none has a reproduction yet, and they are not changed here:packages/i18next/src/useTranslation.js(if (i18n && useSuspense && !ready) use(...)). react-i18next throws the promise instead.packages/livestore/src/useStore.ts(storeOrPromise instanceof Promise ? use(storeOrPromise) : storeOrPromise). Upstream has the same conditionalReact.use, so a seconduseStorecould receive the first store.packages/tanstack-router/src/Match.tsrxMatchInner(the_forcePending→status === 'pending'use()sites share one component's positions). Upstream throws promises.packages/swrpromisefallbackData(use(fallback)only while the cache is empty).Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
Low Risk
Narrow change to suspense promise retention keys in
useQueries; non-suspenseuseQueriesis unaffected, and new tests lock sequential suspense and transition behavior.Overview
Fixes Octane suspense replay when a component uses
useSuspenseQueries()and then another suspense hook in the same render.useQueriesnow keys the retaineduseSuspensePromisememo by every suspense query’squeryHash, not only hashes that are still pending. When the group settled, the old key collapsed and the group stopped callinguse(), so a followinguseSuspenseQuery/useSuspenseQueriescould replay the group’s fulfilled thenable and render withdataundefined (often stuck in@catch).useSuspensePromisedocs now state that the key must stay stable through settling.Tests add sequential suspense conformance and React differential scenarios (
useSuspenseQueries→ singular/grouped), plus auseSuspenseQueriestransition-hold case; audit manifests and a patch changeset are updated.Reviewed by Cursor Bugbot for commit ce1a760. Bugbot is set up for automated code reviews on this repo. Configure here.