Skip to content

fix(hydration): keep a JSX boundary's query across retries and resume reads in returned JSX - #1607

Merged
trueadm merged 3 commits into
mainfrom
fix/tsx-query-get-hydrate-loop
Oct 2, 2026
Merged

trueadm merged 3 commits into
mainfrom
fix/tsx-query-get-hydrate-loop

Conversation

@trueadm

@trueadm trueadm commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

A .tsx component that reads a resumed query$ 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> passed scopedChildrenAsBody(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, tryBlock saw a new tryBody, decided the inputs were superseded, and called clearSignalRetryOwners. 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 .tsrx Field loop under a .tsx app.

Server: a component's returned value rendered outside its signal owner. renderComponentFramed and the root pass called serverComponentOutput(out, scope) after leaving the component's owner frame. A .tsx Field'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 (renderReturnedValue runs in renderBlock's runWithSignalOwner), so it never found the seed.

Changes

  • runtime.ts: childrenTryBlock gives JSX Suspense/ErrorBoundary one stable try body. The children (or the scoped props) travel in the env tuple, the same ABI a compiled @try uses for its captures. A self-retry with unchanged children now keeps its retained attempt, as tryBlock'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: serverComponentOutput takes the component's owner. It normalizes a descriptor (non-HTML) returned value through the existing invokeServerSignalComponent, so the attempt observer and host carriers apply as they do to the body. Compiled HTML and strings return before any owner work.
  • New 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):
    • A .tsx Field reading .get() in its returned JSX resumes server 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.
    • The reported .tsx app shape (<main><Suspense><Mid/></Suspense></main>), where the browser selects an id the server never resolved, loads once and settles for both .tsx and .tsrx Fields. Fails on base: the render guard trips after repeated loads.
    • New children while the first attempt is suspended still restart it, never show the abandoned result, and then retry without reloading (2 loads). Fails on base with 3 loads.

With #1601 merged locally on top, all 8 cases pass, including .tsx app + .tsx Field resuming with zero browser loads. #1601 alone still loops on that shape (26 renders, 25 browser loads).

Validation

  • pnpm format:check (not run; scoped pnpm format:files:check on the touched files passes)
  • pnpm typecheck (not run; scoped pnpm typecheck:files on the touched files passes)
  • pnpm test (not run locally; left to CI)
  • targeted tests: 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

  • Hot paths: compiled server bodies take the same branches as before. Only descriptor-returning components with an owner enter the owner. A JSX Suspense render 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 flagged server-render at +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.
  • The .tsx app 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

  • An agent produced this diff (agent-authored)

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Note

Medium Risk
Touches core client boundary/tryBlock retry 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 .tsx returned JSX.

Client: Boundaries no longer build a fresh try-body closure each render. childrenTryBlock keeps stable bodies and passes children (or scoped props) through the tryBlock env tuple—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: serverComponentOutput can normalize a component’s non-HTML return value inside that component’s signal owner (component frame and root pass now pass owner). 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.

… 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]>
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix labels Oct 2, 2026
@trueadm
trueadm marked this pull request as ready for review October 2, 2026 20:02
@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🔴 bundle-reachability: 4 value(s) increased

Compares 3ec43daa4 with 9e02ebdb5 on the same runner. Timing verdicts require a change beyond the combined margin of error (at least 5%) and one 0.1ms timer tick, with the fastest sample also moving beyond that margin. Workflow run

js-framework: 1k/10k row operations (ms, lower is better)

All 20 timed operations (20 within noise)
target operation base head Δ noise
octane-tsrx run 4.47 5.06 +13.2% ±38% ⚪ within noise
octane-tsrx replace 10.05 10.41 +3.6% ±41% ⚪ within noise
octane-tsrx add 4.79 4.19 −12.5% ±36% ⚪ within noise
octane-tsrx update 0.55 0.61 +10.9% ±77% ⚪ within noise
octane-tsrx select 0.28 0.28 −0.0% ±63% ⚪ within noise
octane-tsrx swap 0.49 0.66 +34.7% ±35% ⚪ within noise
octane-tsrx remove 0.53 0.58 +9.4% ±52% ⚪ within noise
octane-tsrx runlots 41.13 40.63 −1.2% ±41% ⚪ within noise
octane-tsrx select_lots 0.29 0.35 +20.7% ±42% ⚪ within noise
octane-tsrx clear 58.34 52.19 −10.5% ±29% ⚪ within noise
octane-jsx run 5.05 5.22 +3.4% ±57% ⚪ within noise
octane-jsx replace 10.28 10.90 +6.0% ±62% ⚪ within noise
octane-jsx add 4.21 4.59 +9.0% ±52% ⚪ within noise
octane-jsx update 0.79 0.96 +21.5% ±44% ⚪ within noise
octane-jsx select 0.59 0.61 +3.4% ±76% ⚪ within noise
octane-jsx swap 0.89 0.97 +9.0% ±41% ⚪ within noise
octane-jsx remove 0.80 0.80 +0.0% ±68% ⚪ within noise
octane-jsx runlots 39.30 34.84 −11.3% ±35% ⚪ within noise
octane-jsx select_lots 3.63 3.81 +5.0% ±48% ⚪ within noise
octane-jsx clear 53.90 54.27 +0.7% ±23% ⚪ within noise

Application bundle size (bytes)

No changes across 45 measured values.

Public-import reachability bundles (bytes)

target metric base head Δ
server-render raw 64,842 64,882 +40 (+0.1%) 🔴
server-render gzip 22,351 22,378 +27 (+0.1%) 🔴
server-render brotli 20,120 20,169 +49 (+0.2%) 🔴
binding-mantine-hooks-esbuild brotli 29,107 29,110 +3 (+0.0%) 🔴

101 other measured values are unchanged.

trueadm and others added 2 commits October 2, 2026 21:13
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]>
@trueadm
trueadm merged commit f5644f7 into main Oct 2, 2026
31 checks passed
@trueadm
trueadm deleted the fix/tsx-query-get-hydrate-loop branch October 2, 2026 20:40
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant