mirror of https://github.com/sveltejs/svelte
fix: render defaultValue/defaultChecked in SSR (#18446)
defaultValue/defaultChecked are DOM properties, not HTML attributes, so they were being dropped from the SSR output for <input> and <textarea>. This caused non-JS users to see no default and hydrated pages to briefly show the empty state before hydration ran. The compiler now translates: - <input defaultValue=x> -> <input value="x"> - <input defaultChecked> -> <input checked> - <textarea defaultValue=x> -> <textarea>x</textarea> Non-input elements still drop the property (no HTML equivalent). The spread path already handled this at runtime via `$.attributes()`; this keeps the non-spread form symmetric. Adds an SSR regression test covering both static and bound values across text/checkbox/radio inputs and textareas.pull/18452/head
parent
c4daa490bb
commit
de011c19c0
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: render `defaultValue`/`defaultChecked` as SSR-visible `value`/`checked` on `<input>`, and `defaultValue` as text content on `<textarea>`
|
||||
@ -0,0 +1,3 @@
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({});
|
||||
@ -0,0 +1,7 @@
|
||||
<input value="foo"/>
|
||||
<input value="bar"/>
|
||||
<input checked/>
|
||||
<input type="checkbox" checked/>
|
||||
<input type="radio" checked/>
|
||||
<textarea>baz</textarea>
|
||||
<textarea>hello</textarea>
|
||||
@ -0,0 +1,11 @@
|
||||
<script>
|
||||
let value = 'hello';
|
||||
</script>
|
||||
|
||||
<input defaultValue="foo" />
|
||||
<input defaultValue={"bar"} />
|
||||
<input defaultChecked />
|
||||
<input type="checkbox" defaultChecked />
|
||||
<input type="radio" defaultChecked />
|
||||
<textarea defaultValue="baz"></textarea>
|
||||
<textarea defaultValue={value}></textarea>
|
||||
Loading…
Reference in new issue