Skip to content

fix(octane): render a textarea's children as one text value on both sides - #1435

Merged
trueadm merged 6 commits into
mainfrom
claude/pensive-noether-0195fa
Sep 29, 2026
Merged

trueadm merged 6 commits into
mainfrom
claude/pensive-noether-0195fa

Conversation

@trueadm

@trueadm trueadm commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

A <textarea>'s children are now text on both the client and the server. Textarea content is RCDATA: the HTML parser keeps markup and comments inside it as literal text, so no template placeholder or hydration marker can live there.

Before this change:

  • <textarea>hello {v as string}</textarea> threw Cannot read properties of null (reading 'parentNode') on a client-only mount. The client template embedded <!> inside the textarea, which the parser turned into text, so the compiled walk found no placeholder.
  • The server wrote <textarea>hello <!-- -->A</textarea>, so the default value before hydration was literally hello <!-- -->A, and hydration reported a mismatch.
  • <textarea>hello {v}</textarea> and <textarea>{a}{b}</textarea> mounted with a literal <!> in the value, and hydration rebuilt the textarea.
  • An element or array as a textarea's sole child: the server wrote <!--[--><p>x</p><!--]--> as text, the client inserted a real <p> that the value ignores, and hydration abandoned root adoption.

Contract

  • All of a textarea's children fold into one text value. The client binds it as the host's only Text node through the new runtime helper textareaText, and the server serializes it markerless through ssrTextareaText. A leading newline is still doubled for the parser.
  • Holes keep their usual text rules. {x} renders strings and numbers, renders null, undefined and booleans as nothing, and joins arrays or iterables of text. {x as string} stringifies like any text binding (true → "true").
  • An element, function or other object throws a new error, code 336, on both sides. An element, component, @if/@for/@switch/@try, JSX expression or <title> written inside a textarea is a compile error on both emit paths. A textarea in the SVG namespace is unchanged.
  • The same rule covers the other routes to a textarea: createElement descriptors and stored JSX (pure-host and block-backed de-opt paths, plus ssrHostElement), and a children prop from a spread (childTextHole and ssrChildrenSources). A descriptor's tag matches case-insensitively, so createElement('TEXTAREA', …) folds on the client exactly as the server's lowercased tag does.
  • Signal handles in a compiled textarea's holes stay live. textareaText returns one derived handle over the parts, so the existing direct text binding subscribes to each signal. A descriptor textarea takes text children only; the raw de-opt reconciler never supported handle children.
  • React allows at most one child and converts it with '' + children, so an element becomes [object Object] and false becomes "false". The divergence is documented in docs/differences-from-react.md.

Change to #1430's textarea cases

#1430 (merged while this PR was open) pinned a different textarea outcome in mismatch-structural.test.ts: an element value in a textarea's hole kept the server text and rendered the element beside it (A<em class="waits">R</em> inside the textarea). That conflicts with this PR's contract, so:

  • "keeps a textarea host's server text…" became "rejects an element value inside a textarea on both sides". It asserts the server throws, and that the client reports the same error once through onUncaughtError with no recoverable-error reports.
  • The suspending-hole fixture no longer puts an element in a textarea. Its subject, the <div> hole reporting once and building once, is unchanged.
  • fix(octane): discard server text an only-child hole's element value cannot adopt #1430's runtime branch that keeps a textarea's server text in hydrateOnlyChild stays. It is now reached only by a signal handle passed straight to childTextHole.

Validation

  • pnpm format:files:check on every changed file (not the repo-wide pnpm format:check)
  • pnpm typecheck:files on the changed TS/TSRX files, with tsrx-tsc (not the repo-wide pnpm typecheck)
  • pnpm test: not run in full locally, which runs out of memory here. I ran the relevant Vitest projects instead:
    • octane + octane-prod in full, before the final merge of main: 25,313 / 25,313 pass.
    • The same run after merging main: 25,817 / 25,823. The 6 failures all pass when rerun in isolation. Four were 5 s timeouts (hmr.test.ts, independent-island, independent-parent). Two were behavior-root "(prod)" textarea retirement tests whose root was never created under load; they pass 3 of 3 in isolation. I'm treating these as load flakes, and CI will confirm.
    • Binding projects with textareas: textarea-autosize (+differential, +ssr), html-react-parser, hook-form (+server), shadcn (+ssr), aria-ssr, base-ui-ssr, mdx and vite-plugin all pass (1,917 tests).
  • targeted tests:
    • New packages/octane/tests/hydration/textarea-children-hydrate.test.ts, which runs in dev and prod. It covers server serialization, hydration adoption with no recoverable errors or reports, updates, client-only mount and update, signal parts, and non-text values throwing on both sides. 100 of its 104 original cases fail on the pre-fix source; the 4 that pass are controls.
    • New cases in packages/octane/tests/compiler/compile-errors.test.ts for markup, components, directives and <title> inside a textarea, plus an SVG-namespace control.
    • Re-run on the merged head together with spread-sole-child-hydrate, client-host-source-aggregation, folded-head-prefix-hydrate, subtemplate-own-locals and head-hydrate: all pass.
  • Latest head (4dc758f: Bugbot fix plus main with fix(octane): discard server text an only-child hole's element value cannot adopt #1430 merged):
    • textarea-children-hydrate and mismatch-structural pass in dev and prod (96 and 316 tests). The new uppercase-tag cases fail with the old exact check.
    • A full octane + octane-prod run on a machine at load average 33–44 failed only in unrelated files: 5 s/15 s timeouts, and behavior-root textarea-retirement tests whose fixtures use value props with no children. That fixture compiles byte-identically on the client against main. On the server it differs only by the new ssrChildrenSources textarea flag, which is inert without a spread children. The previous head's CI, including all four test shards, was green.
  • pnpm error-codes:check and pnpm sync. Sync regenerated only packages/cli/src/data/octane-data.json for error 336.

Bundle size, from benchmarks/bundle-size/run-minimal.mjs on the same machine, baseline against this change:

scenario raw gzip brotli
root-static, base-ui, radix, apollo (general client runtime) +700 to +704 +200 to +236 +45 to +349
server-render +652 +198 +116
every other minimal scenario 0 0 0

No budget is newly exceeded. capture-only, hydrate-root, deferred-hydration, suspense-transition, server-render and apollo were already over budget on the baseline. Routing de-opt textareas through the derived signal handle as well would have cost about another 200 B gzip on every general-runtime app, so the de-opt path takes text only.

Risk / follow-ups

  • A children prop supplied through a spread still resets to an empty default value on update. That is the applyFormControlValues reset: fix(octane): serialize a spread host's sole child unframed and keep textarea children live #1432 fixed it for authored children but not for a spread-held children source. I filed a separate task; the new test covers that case's serialization and hydration only.
  • In a compiled textarea, a signal handle among the parts re-subscribes on each re-render, because the derived handle is recreated.
  • Any uppercase de-opt host, e.g. createElement('DIV'), is still rebuilt on each client render and on hydration, because the client matches localName against the authored type exactly. This predates the PR and is not textarea-specific; it is filed as a separate task.
  • Not handled: a dynamic <Tag> that resolves to textarea at runtime (its children compile as an ordinary children template); authored DOM binding views (dom-binding-program); and a textarea with dangerouslySetInnerHTML, which React rejects anyway.

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 compiler emission, client hydration, and SSR for a form-control host where RCDATA semantics must stay aligned; scope is narrow but incorrect behavior would affect every multi-child textarea and createElement paths.

Overview
<textarea> children now fold into a single text default value on the client and server, avoiding hydration markers (<!>, <!-- -->) that HTML treats as literal textarea content and that previously caused mismatches, null-mount crashes, and literal placeholder text in the value.

The compiler adds a dedicated multi-child path (textareaTextParts → runtime textareaText / ssrTextareaText) instead of per-child slots with markers. textareaChildText centralizes text coercion (strings, numbers, joined arrays/iterables; nullish/booleans empty). Non-text children (elements, functions, objects) throw error 336 at runtime and are compile errors for markup, components, and template directives inside <textarea> (HTML namespace only; SVG unchanged).

The same rule applies to createElement / stored JSX (deoptHostChildren, ssrHostElement), and to a children prop from a spread (ssrChildrenSources, childSlot). Compiled textareas with signal holes get one derived signal handle over the joined parts. Docs and a changeset describe the React divergence (React stringifies a single child with '' + children).

Reviewed by Cursor Bugbot for commit 4dc758f. Bugbot is set up for automated code reviews on this repo. Configure here.

trueadm and others added 4 commits September 29, 2026 23:15
…ides

Textarea content is RCDATA: the HTML parser keeps markup and comments inside
it as literal text. A textarea with more than one child compiled to a client
template with `<!>` placeholders inside the textarea (a client-only mount
threw reading `parentNode` of null) and a server frame such as
`hello <!-- -->A`, so the pre-hydration value held the markers and hydration
reported a mismatch or rebuilt the root.

A textarea's children now fold into one text value. The compiler binds it as
the host's only Text node through `textareaText` and the server serializes it
markerless through `ssrTextareaText`. Descriptor textareas (createElement,
stored JSX) and a children prop from a spread follow the same rule. Strings and
numbers render, empty values render nothing, arrays and iterables join, and any
other value throws error 336 on both sides. Markup or a template directive
written inside a textarea is a compile error. Signal handles in a compiled
textarea's holes stay live through one derived handle over the parts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The spread textarea default reset is fixed on main (#1432), so the spread
cases now join the shared mount, hydrate and update matrix.

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 Sep 29, 2026
@github-actions
github-actions Bot marked this pull request as draft September 29, 2026 22:26

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Uppercase textarea deopt skips text fold
    • Replaced raw descriptor type comparisons (d.type/value.type === 'textarea') with el.localName === 'textarea' in both deoptHostChildren and reconcileDeoptNode, since the DOM always lowercases localName regardless of the authored createElement spelling, matching the server's tag.toLowerCase() normalization.

Create PR

Or push these changes by commenting:

@cursor push b52c93f081
Preview (b52c93f081)
diff --git a/packages/octane/src/runtime.ts b/packages/octane/src/runtime.ts
--- a/packages/octane/src/runtime.ts
+++ b/packages/octane/src/runtime.ts
@@ -32083,7 +32083,7 @@
 		if (!hasHostPropContent(value)) {
 			reconcileDeoptChildren(
 				el,
-				value.type === 'textarea' && elNs === undefined
+				el.localName === 'textarea' && elNs === undefined
 					? textareaChildText(value.children, rejectTextareaChild)
 					: value.children,
 				ownerBlock,
@@ -32664,7 +32664,7 @@
 	elNs: string | undefined,
 	adopt = false,
 ): void {
-	if (d.type !== 'textarea' || elNs !== undefined) {
+	if (el.localName !== 'textarea' || elNs !== undefined) {
 		childSlot(block, 0, el, d.children, null, false, el);
 		return;
 	}

You can send follow-ups to the cloud agent here.

Reviewed by Cursor Bugbot for commit 24a56e5. Configure here.

Comment thread packages/octane/src/runtime.ts Resolved
@trueadm
trueadm marked this pull request as ready for review September 29, 2026 23:03
HTML tag names are ASCII case-insensitive, and ssrHostElement folds a
descriptor textarea's children on the lowercased tag. The client compared
the authored type exactly, so `createElement('TEXTAREA', null, 'a', list)`
still reconciled its children as a keyed list and left range comments
inside the textarea. Both de-opt paths now share a case-insensitive check
that compares the string before any DOM read.

With main merged, the only-child hole tests from #1430 expected an element
value inside a textarea to render beside the server text. A textarea's
children are text on both sides now, so that case asserts the error on the
server and through onUncaughtError on the client, and the suspending-hole
fixture no longer puts an element in a textarea.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trueadm
trueadm merged commit 25b6e6d into main Sep 29, 2026
31 checks passed
@trueadm
trueadm deleted the claude/pensive-noether-0195fa branch September 29, 2026 23:49
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