Repository navigation
fix(hydration): keep a JSX boundary's query across retries and resume reads in returned JSX - #1607
Merged
Merged
Conversation
… reads in returned JSX A JSX <Suspense>/<ErrorBoundary> built a new try body closure on every render, so a boundary retrying its own suspended first attempt looked like it had new inputs and retired the attempt's retained signal owners. Each retry then created a fresh query and started another load. A load that resolves in a microtask re-rendered forever and starved timers. Pass the children through the try env tuple with one stable body, as compiled @Try does, so only new children restart the attempt. On the server, renderComponentFramed and the root pass normalized a component's returned value after leaving its signal owner. A lazy read in the returned JSX, such as a .tsx `value$.get()` inside a scoped child, then resolved its query under the parent's instance key. The client renders the returned value inside the component's owner, so it missed the seed. Render the returned value inside the component's owner. Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm
marked this pull request as ready for review
October 2, 2026 20:02
Contributor
Benchmark report
Compares js-framework: 1k/10k row operations (ms, lower is better)All 20 timed operations (20 within noise)
Application bundle size (bytes)No changes across 45 measured values. Public-import reachability bundles (bytes)
101 other measured values are unchanged. |
Fold the owner into serverComponentOutput and reuse invokeServerSignalComponent instead of a second synchronous fast path. Only descriptor-returning components reach it, and the server-render reachability bundle grows by 40 raw bytes instead of 330. Co-Authored-By: Claude Opus 5.5 <[email protected]>
4 of 7 tasks
trueadm
added a commit
that referenced
this pull request
Oct 2, 2026
…another request (#1618) A hydration frame rejected a resource seed whose request no longer matched the client's selection with a hard SignalFrameError ("The presented query definition does not match"), even under the native adoption resolver. The live binding already treats a seed for another request as no seed and starts the client load, so only the historical read failed. The frame now leaves such a read to the live graph during hydration, exactly like a request the server never seeded: the client loads its own selection once, the boundary (or root) waits for it, and adoption keeps the server's nodes while reporting changed text as a recoverable hydration mismatch. An explicit `beginAdoption` frame keeps the error, since it has no live fallback. The defect predates #1601: a `.tsrx` app whose props select another request than the server's already failed. #1601 gave `.tsx` returned-JSX components the server's owner key, which exposed it to #1607's tests, whose browser-only selection previously landed under an unseeded owner. Co-authored-by: Claude Opus 5.5 <[email protected]>
2 of 5 tasks
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
A
.tsxcomponent that reads a resumedquery$with.get()during render re-rendered forever on the client after hydration. The loop starved timers, so a test timeout never fired. There were two independent root causes, one on each side.Client: a JSX boundary retired its own retry's queries.
<Suspense>and<ErrorBoundary>passedscopedChildrenAsBody(props)as the try body, which is a new closure on every render. When the boundary re-renders itself to retry a suspended first hydration attempt,tryBlocksaw a newtryBody, decided the inputs were superseded, and calledclearSignalRetryOwners. The retry then minted a fresh owner, a fresh query, and another load. With a load that resolves in a microtask, that cycle never ended. Any query the browser has to load below a JSX<Suspense>triggers it: a missing seed, or (before #1601) mismatched owner keys. That is why the reporter saw even a.tsrxField loop under a.tsxapp.Server: a component's returned value rendered outside its signal owner.
renderComponentFramedand the root pass calledserverComponentOutput(out, scope)after leaving the component's owner frame. A.tsxField's<output>{String(value$.get())}</output>lowers to a scoped element whose children thunk runs during that normalization. Its query was therefore created under Mid's instance key and loaded twice on the server. The client renders the returned value inside Field's owner (renderReturnedValueruns inrenderBlock'srunWithSignalOwner), so it never found the seed.Changes
runtime.ts:childrenTryBlockgives JSXSuspense/ErrorBoundaryone stable try body. The children (or the scoped props) travel in theenvtuple, the same ABI a compiled@tryuses for its captures. A self-retry with unchanged children now keeps its retained attempt, astryBlock's "unchanged inputs retry its preserved tree and native query owners" contract intends. New children still supersede and restart the attempt. Function (compiled) children are unchanged.runtime.server.ts:serverComponentOutputtakes the component's owner. It normalizes a descriptor (non-HTML) returned value through the existinginvokeServerSignalComponent, so the attempt observer and host carriers apply as they do to the body. Compiled HTML and strings return before any owner work.tests/hydration/returned-jsx-query-resume.test.ts(cold SSR→hydrate scenarios, dev and prod compile, with a render-count guard that throws instead of hanging):.tsxField reading.get()in its returned JSX resumesserver a. The browser loader is never called, and the<output>node is adopted. Fails on base: the server loads twice, then the browser loads and reports a mismatch..tsxapp shape (<main><Suspense><Mid/></Suspense></main>), where the browser selects an id the server never resolved, loads once and settles for both.tsxand.tsrxFields. Fails on base: the render guard trips after repeated loads.With #1601 merged locally on top, all 8 cases pass, including
.tsxapp +.tsxField resuming with zero browser loads. #1601 alone still loops on that shape (26 renders, 25 browser loads).Validation
pnpm format:check(not run; scopedpnpm format:files:checkon the touched files passes)pnpm typecheck(not run; scopedpnpm typecheck:fileson the touched files passes)pnpm test(not run locally; left to CI)vitest run --project octane packages/octane/tests/hydration/returned-jsx-query-resume.test.ts: 8/8 pass on the rebased head. Each fix was reverted separately against the base commit to confirm its cases fail: client fix reverted, 6/8 fail; server fix reverted, 6/8 fail.Risk / follow-ups
Suspenserender allocates a one-element env array instead of a closure. While a transition is active, a changed env is journaled like a compiled@try's. The bench report flaggedserver-renderat +330 raw bytes on the first head. Reusing the existing invoker brings it to +40 raw (run-minimal.mjs --budgets server-render: base 64,842 → 64,882). That bundle's committed 54,048 budget already fails on base..tsxapp shape resumes (rather than refetching once) only together with fix(hydration): key signal owners below returned JSX by authored invocations only #1601's owner-key fix. Each PR stands alone.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
Medium Risk
Touches core client boundary/
tryBlockretry semantics and server SSR signal-owner wiring for every component return path; behavior change is intentional but affects hot hydration and query resume paths.Overview
Fixes two hydration bugs around
query$under JSX<Suspense>/<ErrorBoundary>and in.tsxreturned JSX.Client: Boundaries no longer build a fresh try-body closure each render.
childrenTryBlockkeeps stable bodies and passes children (or scoped props) through thetryBlockenvtuple—same pattern as compiled@try—so a self-retry with unchanged children keeps the suspended attempt and its queries instead of clearing owners and reloading forever.Server:
serverComponentOutputcan normalize a component’s non-HTML return value inside that component’s signal owner (component frame and root pass now passowner).query$reads in returned JSX seed under the declaring component’s identity, aligning with the client and avoiding double server loads / mismatch refetches.Adds
returned-jsx-query-resume.test.ts(SSR→hydrate, dev/prod) with a render-count guard for the infinite-loop case, plus an octane patch changeset.Reviewed by Cursor Bugbot for commit a10c429. Bugbot is set up for automated code reviews on this repo. Configure here.