Skip to content

Commit 077c787

Browse files
ryansolidClaude via Cursorcursoragent
authored
fix(compilers): textarea value fold must not reserve a hydration id (#3691) (#3696)
* fix(compilers): textarea value fold must not reserve a hydration id (#3691) The SSR textarea value/defaultValue fold turns the attribute into a dynamic text child, and that child took the `_$scope` hydration-id reservation a dynamic hole gets. The client writes the value as a plain property effect that never allocates an id, so every component after the textarea hydrated one id off and its updates targeted detached DOM. Treat the fold like the innerHTML/textContent redirects (#3015): opaque content, no reservation. Babel flags the folded container with _childProperty; the native compiler skips the reservation for a children_replacement. Shared fixture + parity-harness scenario added. Co-authored-by: Claude via Cursor <[email protected]> Co-authored-by: Cursor <[email protected]> * fix(babel-plugin): use the local @babel/types namespace in the textarea fold flag The fold's _childProperty cast referenced `babelTypes`, which utils.ts does not import (it aliases @babel/types as `t`). Rollup's transpile let it through; the typecheck step did not. Co-authored-by: Claude via Cursor <[email protected]> Co-authored-by: Cursor <[email protected]> --------- Co-authored-by: Claude via Cursor <[email protected]> Co-authored-by: Cursor <[email protected]>
1 parent 61a33af commit 077c787

8 files changed

Lines changed: 109 additions & 2 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@solidjs/babel-plugin": patch
3+
"@solidjs/compiler": patch
4+
---
5+
6+
A `<textarea>` with a dynamic `value`/`defaultValue` no longer desyncs hydration ids for the siblings after it (#3691). The server folds the value into the textarea's text content, and that fold was taking the `_$scope` hydration-id reservation a dynamic child hole gets — but the client writes the value as a plain property effect that never allocates an id, so every component after the textarea hydrated one id off and its updates targeted detached DOM. The fold is now treated like the `innerHTML`/`textContent` redirects (#3015): opaque content, no id reservation, in both the Babel plugin and the native compiler.

‎packages/babel-plugin/src/shared/utils.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,13 @@ export function transformSpecialCaseAttributes(
866866
child.extra = { raw: text, rawValue: text };
867867
} else {
868868
child = t.jsxExpressionContainer(value);
869+
// The folded value is the textarea's text content on the server, but
870+
// the client writes it as a plain `value` property effect that never
871+
// allocates a hydration id. Flag it like the innerHTML/textContent
872+
// redirects (#3015) so the SSR child pipeline skips the `_$scope` id
873+
// reservation — otherwise the reservation shifts every keyed sibling
874+
// after the textarea by one id (#3691).
875+
(child as t.JSXExpressionContainer & { _childProperty?: boolean })._childProperty = true;
869876
}
870877
path.node.children = [child];
871878
attr.remove();

‎packages/babel-plugin/test/__ssr_hydratable_fixtures__/attributeExpressions/code.js‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,18 @@ const template98 = (
391391
</div>
392392
);
393393

394+
// solidjs/solid#3691: a textarea's dynamic value/defaultValue folds into its
395+
// text content on the server, but the client writes it as a plain `value`
396+
// property effect that never allocates a hydration id — the fold must not take
397+
// the _$scope reservation either, or the component after it hydrates one id off.
398+
const template99 = (
399+
<div>
400+
<textarea value={text()} />
401+
<textarea defaultValue={initial()} />
402+
<Counter />
403+
</div>
404+
);
405+
394406
// Static attributes after the last spread bake into ssrElement's attribute
395407
// string with their keys skipped on the spread; statics before a spread, and
396408
// anything between two spreads, stay a source the spread can override.

‎packages/babel-plugin/test/__ssr_hydratable_fixtures__/attributeExpressions/output.js‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,14 @@ var _tmpl$ = ['<a href="/" class="', '">Welcome</a>'],
7070
'></video><video src="test.mp4" muted></video></div>'
7171
],
7272
_tmpl$49 = ["<video", ' src="test.mp4" muted></video>'],
73-
_tmpl$50 = ["<div", "><div>", "</div><div>", '</div><input type="checkbox"', "></div>"];
73+
_tmpl$50 = ["<div", "><div>", "</div><div>", '</div><input type="checkbox"', "></div>"],
74+
_tmpl$51 = [
75+
"<div",
76+
"><textarea>",
77+
"</textarea><textarea>",
78+
"</textarea><!--$-->",
79+
"<!--/--></div>"
80+
];
7481
var _sk$ = k => k === "foo" || k === "disabled" || k === "title" || k === "style" || k === "class",
7582
_sk$2 = k => k === "class" || k === "style",
7683
_sk$3 = k => k === "something",
@@ -623,6 +630,16 @@ var _v$118 = _$ssrHydrationKey(),
623630
_v$121 = () => _$ssrAttribute("checked", _$escape(checked(), true));
624631
const template98 = _$ssr(_tmpl$50, _v$118, _v$119, _v$120, _v$121);
625632

633+
// solidjs/solid#3691: a textarea's dynamic value/defaultValue folds into its
634+
// text content on the server, but the client writes it as a plain `value`
635+
// property effect that never allocates a hydration id — the fold must not take
636+
// the _$scope reservation either, or the component after it hydrates one id off.
637+
var _v$122 = _$ssrHydrationKey(),
638+
_v$123 = () => _$escape(text()),
639+
_v$124 = () => _$escape(initial()),
640+
_v$125 = _$escape(Counter({}));
641+
const template99 = _$ssr(_tmpl$51, _v$122, _v$123, _v$124, _v$125);
642+
626643
// Static attributes after the last spread bake into ssrElement's attribute
627644
// string with their keys skipped on the spread; statics before a spread, and
628645
// anything between two spreads, stay a source the spread can override.

‎packages/compiler/__tests__/fixtures/ssr-hydratable/attributeExpressions/output.js‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,13 @@ var _tmpl$52 = [
171171
"</div><input type=\"checkbox\"",
172172
"></div>"
173173
];
174+
var _tmpl$53 = [
175+
"<div",
176+
"><textarea>",
177+
"</textarea><textarea>",
178+
"</textarea><!--$-->",
179+
"<!--/--></div>"
180+
];
174181
var _sk$ = (k) => k === "foo" || k === "disabled" || k === "title" || k === "style" || k === "class";
175182
var _sk$2 = (k) => k === "class" || k === "style";
176183
var _sk$3 = (k) => k === "something";
@@ -552,6 +559,16 @@ var _v$120 = _$ssrHydrationKey(), _v$121 = () => {
552559
// applies these as plain prop effects that never allocate hydration ids), or
553560
// every hydratable sibling after it shifts by one id.
554561
const template98 = _$ssr(_tmpl$52, _v$120, _v$121, _v$122, _v$123);
562+
var _v$124 = _$ssrHydrationKey(), _v$125 = () => {
563+
return _$escape(text());
564+
}, _v$126 = () => {
565+
return _$escape(initial());
566+
}, _v$127 = _$escape(Counter({}));
567+
// solidjs/solid#3691: a textarea's dynamic value/defaultValue folds into its
568+
// text content on the server, but the client writes it as a plain `value`
569+
// property effect that never allocates a hydration id — the fold must not take
570+
// the _$scope reservation either, or the component after it hydrates one id off.
571+
const template99 = _$ssr(_tmpl$53, _v$124, _v$125, _v$126, _v$127);
555572
// Static attributes after the last spread bake into ssrElement's attribute
556573
// string with their keys skipped on the spread; statics before a spread, and
557574
// anything between two spreads, stay a source the spread can override.

‎packages/compiler/src/ssr/transform.rs‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2501,7 +2501,16 @@ impl<'a, 'source> AstSsrTransform<'a, 'source> {
25012501
let dynamic =
25022502
self.classify()
25032503
.is_dynamic(Some(container.span.start), &expression, false);
2504-
let allocates = self.hydratable && child_slot_allocates_ids(child);
2504+
// A `children_replacement` is the textarea `value` /
2505+
// `defaultValue` fold: text content on the server, but a
2506+
// plain `value` property effect on the client that never
2507+
// allocates a hydration id. Like the innerHTML/textContent
2508+
// redirects (#3015) it must not take the `_$scope` id
2509+
// reservation, or every keyed sibling after the textarea
2510+
// hydrates one id off (#3691).
2511+
let allocates = self.hydratable
2512+
&& children_replacement.is_none()
2513+
&& child_slot_allocates_ids(child);
25052514
// Function children are scope-eligible like dynamic ones —
25062515
// see the template-children path above.
25072516
let function_hole = expression_is_function_shaped(&expression);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "textarea-value-id-parity",
3+
"shell": "<main _hk=0><textarea>test</textarea><!--$--><button _hk=1>0</button><!--/--></main>",
4+
"rest": ""
5+
}

‎packages/web/test/harness/scenarios.tsx‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,6 +1616,32 @@ function InnerHTMLCallSiblings() {
16161616
);
16171617
}
16181618

1619+
// ---------------------------------------------------------------------------
1620+
// solidjs/solid#3691: a textarea's dynamic `value` folds into its text content
1621+
// on the server, but the client writes it as a plain `value` property effect
1622+
// with no owner. Pre-fix the server's `_$scope` reservation on the fold
1623+
// consumed a hydration id the client never allocated, so the component after
1624+
// the textarea hydrated one id off — its button went unclaimed and the click
1625+
// updated detached DOM.
1626+
let textareaCounterButton!: HTMLButtonElement;
1627+
function TextareaSiblingCounter() {
1628+
const [count, setCount] = createSignal(0);
1629+
return (
1630+
<button ref={textareaCounterButton} onClick={() => setCount(c => c + 1)}>
1631+
{count()}
1632+
</button>
1633+
);
1634+
}
1635+
function TextareaValueSiblings() {
1636+
const [text] = createSignal("test");
1637+
return (
1638+
<main>
1639+
<textarea value={text()} />
1640+
<TextareaSiblingCounter />
1641+
</main>
1642+
);
1643+
}
1644+
16191645
// ---------------------------------------------------------------------------
16201646
// solidjs/solid#3105: a reactive lone spread passes its accessor straight to
16211647
// spread() on the client — no mergeProps, no memo, no hydration id — matching
@@ -2758,6 +2784,14 @@ export const scenarios: Scenario[] = [
27582784
expectedTextAfterUpdate: "r1r2on",
27592785
stableSelector: "div, label"
27602786
},
2787+
{
2788+
name: "textarea-value-id-parity",
2789+
App: TextareaValueSiblings,
2790+
expectedText: "test0",
2791+
update: () => textareaCounterButton.click(),
2792+
expectedTextAfterUpdate: "test1",
2793+
stableSelector: "main, textarea, button"
2794+
},
27612795
{
27622796
name: "reactive-lone-spread-id-parity",
27632797
App: ReactiveLoneSpread,

0 commit comments

Comments
 (0)