Skip to content

fix(compiler): fold tsx string-literal children for hydration - #972

Merged
jonkwheeler merged 1 commit into
mainfrom
cursor/fix-tsx-string-literal-hydration-f5bf
Sep 6, 2026
Merged

jonkwheeler merged 1 commit into
mainfrom
cursor/fix-tsx-string-literal-hydration-f5bf

Conversation

@jonkwheeler

@jonkwheeler jonkwheeler commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #965

Summary

  • .tsx return-form extraction treated string-literal children such as Prettier's {" "} as dynamic hN holes, while the server and .tsrx compilers baked them into the template.
  • That hole-count mismatch made hydration consume the next sibling for the whitespace slot and remount a duplicate element (itemsitems).
  • extractFragment now leaves string-literal expression children in place so emitElementHtml folds them through staticTextLiteral, matching .tsrx and the server.

Why

  • Hydration requires client and server templates to agree on hole count and positions.
  • Folding the literals (instead of keeping them dynamic on both sides) matches the existing .tsrx / server contract and avoids a runtime text hole for constant whitespace.

Changes

  • packages/octane/src/compiler/compile.js: do not hoist staticTextLiteral children in extractFragment.
  • Compiler regression for Prettier {" "}, adjacent/{""} literals, and still-dynamic {expr as string} holes.
  • Hydration regression: adopt one link, no duplicates, client-only mount matches SSR.

Validation

  • targeted tests: packages/octane/tests/compiler/tsx-static-string-child.test.ts, packages/octane/tests/hydration/tsx-string-literal-hydrate.test.ts (12 passed, including octane-prod)
  • nearby: ssr-tsx-children, text-sibling-hydrate, markerless-text-hydrate, value-jsx-hydrate, component-children-hydrate (88 passed)
  • pnpm format:files:check on changed files
  • ./node_modules/.bin/tsgo --noEmit -p packages/octane/tsconfig.json
  • pnpm format:check (CI lint on 31b2912df)
  • pnpm typecheck (CI typecheck on 31b2912df)
  • pnpm test (CI test shards + test (24) on 31b2912df)
  • pnpm sync (no extra generated diff)
  • Current-head CI is green: required lint, typecheck, test, React parity, examples, website, heavy integration, and provenance all succeeded. GitHub reports mergeable.

Risk / follow-ups

  • Only string Literal / StringLiteral children are folded, the same set staticTextLiteral already bakes on the template path. {expr as string}, numbers, and other expressions stay holes.
  • Compile-time only; fewer client holes than before. No trustworthy wall-clock measurement for this fold; residual risk is an untested parenthesized/template-literal constant that both sides already leave dynamic.

Reviewers

Requested: @leonidaz @trueadm

READY FOR REVIEW

Provenance

  • An agent produced this diff (agent-authored)
Open in Web Open in Cursor 

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

Leave {" "} and other string-literal expression children in extracted
.tsx fragments so the client bakes them like .tsrx and the server.
That keeps hole counts aligned and stops hydration from duplicating
the following element.

Fixes #965

Co-authored-by: Jon Wheeler <[email protected]>
@jonkwheeler
jonkwheeler marked this pull request as ready for review September 6, 2026 13:53
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix labels Sep 6, 2026
@jonkwheeler
jonkwheeler merged commit eb32683 into main Sep 6, 2026
47 of 50 checks passed
@jonkwheeler
jonkwheeler deleted the cursor/fix-tsx-string-literal-hydration-f5bf branch September 6, 2026 14:08
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.

TSX: String literal expression (e.g. {" "}) causes SSR/client hole count mismatch and hydration element duplication

3 participants