Skip to content

Commit b64071c

Browse files
authored
fix(web): render textarea spread values as content (#3287)
Closes #3286
1 parent b1b38c3 commit b64071c

3 files changed

Lines changed: 45 additions & 1 deletion

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solidjs/web": patch
3+
---
4+
5+
Render textarea values supplied through SSR spreads as text content rather than invalid HTML attributes.

‎packages/web/src/server.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3569,6 +3569,15 @@ export function ssrElement(tag, props, children, needsId) {
35693569
let result = `<${tag}${hk} `;
35703570
for (let i = 0; i < keys.length; i++) {
35713571
const prop = keys[i];
3572+
const value = props[prop];
3573+
// The compiler moves static textarea values into children, but an
3574+
// element with a spread is serialized here instead. Keep the runtime
3575+
// path equivalent: textarea value/defaultValue are its text content,
3576+
// never HTML attributes.
3577+
if (tag === "textarea" && (prop === "value" || prop === "defaultValue")) {
3578+
if (value !== null) children = escape(value);
3579+
continue;
3580+
}
35723581
if (ChildProperties.has(prop)) {
35733582
if (children === undefined && !skipChildren)
35743583
children =
@@ -3577,7 +3586,6 @@ export function ssrElement(tag, props, children, needsId) {
35773586
: escape(props[prop]);
35783587
continue;
35793588
}
3580-
const value = props[prop];
35813589
if (prop === "style") {
35823590
result += `style="${ssrStyle(value)}"`;
35833591
} else if (prop === "class") {

‎packages/web/test/server/spread-function-source.spec.tsx‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,37 @@ describe("SSR spread with function source (#2815)", () => {
3232
expect(html).toContain('id="y"');
3333
});
3434

35+
test("textarea value from props merged around a spread becomes text content (#3286)", () => {
36+
const value = () => "something";
37+
const html = renderToString(() => <textarea {...{ "data-x": "x" }} value={value()} />);
38+
39+
expect(html).toMatch(/data-x="x"\s*>something<\/textarea>/);
40+
expect(html).not.toContain(' value="something"');
41+
});
42+
43+
test("textarea value supplied by a spread becomes text content (#3286)", () => {
44+
const html = renderToString(() => <textarea {...{ "data-x": "x", value: "something" }} />);
45+
46+
expect(html).toMatch(/data-x="x"\s*>something<\/textarea>/);
47+
expect(html).not.toContain(' value="something"');
48+
});
49+
50+
test("textarea value before a spread remains text content (#3286)", () => {
51+
const html = renderToString(() => <textarea value="something" {...{ "data-x": "x" }} />);
52+
53+
expect(html).toMatch(/data-x="x"\s*>something<\/textarea>/);
54+
expect(html).not.toContain(' value="something"');
55+
});
56+
57+
test("textarea defaultValue supplied by a spread becomes text content (#3286)", () => {
58+
const html = renderToString(() => (
59+
<textarea {...{ "data-x": "x", defaultValue: "something" }} />
60+
));
61+
62+
expect(html).toMatch(/data-x="x"\s*>something<\/textarea>/);
63+
expect(html).not.toContain(' defaultValue="something"');
64+
});
65+
3566
test("Dynamic routes spreads through mergeProps", () => {
3667
const props = { "data-x": "1", id: "y" };
3768
const html = renderToString(() => <Dynamic component="div" {...props} />);

0 commit comments

Comments
 (0)