mirror of https://github.com/sveltejs/svelte
fix: ensure bound input content is resumed on hydration (#11986)
* fix: ensure bound input content is resumed on hydration * fix: ensure bound input content is resumed on hydration * Update packages/svelte/src/internal/client/dom/elements/bindings/input.js Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com> * fix: ensure bound input content is resumed on hydration * fix: ensure bound input content is resumed on hydration * Update packages/svelte/src/internal/client/dom/elements/bindings/input.js Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com> * add test * add test * add test * add test * Update packages/svelte/src/internal/client/dom/elements/bindings/input.js Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com> * add test * add test * newlines between multi-line blocks, let the code breathe --------- Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com> Co-authored-by: Rich Harris <rich.harris@vercel.com>pull/12009/head
parent
f1c9edcc63
commit
0d51dbae32
@ -0,0 +1,5 @@
|
||||
---
|
||||
"svelte": patch
|
||||
---
|
||||
|
||||
fix: ensure bound input content is resumed on hydration
|
@ -0,0 +1,18 @@
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
skip_mode: ['client'],
|
||||
|
||||
test({ assert, target, hydrate }) {
|
||||
const inputs = /** @type {NodeListOf<HTMLInputElement>} */ (target.querySelectorAll('input'));
|
||||
inputs[1].checked = true;
|
||||
inputs[1].dispatchEvent(new window.Event('change'));
|
||||
// Hydration shouldn't reset the value to 1
|
||||
hydrate();
|
||||
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
'<input name="foo" type="radio" value="1"><input name="foo" type="radio" value="2"><input name="foo" type="radio" value="3">\n2'
|
||||
);
|
||||
}
|
||||
});
|
@ -0,0 +1,9 @@
|
||||
<script>
|
||||
let value = $state(1);
|
||||
</script>
|
||||
|
||||
{#each [1, 2, 3] as number}
|
||||
<input type="radio" name="foo" value={number} bind:group={value}>
|
||||
{/each}
|
||||
|
||||
{value}
|
@ -0,0 +1,15 @@
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
skip_mode: ['client'],
|
||||
|
||||
test({ assert, target, hydrate }) {
|
||||
const input = /** @type {HTMLInputElement} */ (target.querySelector('input'));
|
||||
input.value = 'foo';
|
||||
input.dispatchEvent(new window.Event('input'));
|
||||
// Hydration shouldn't reset the value to empty
|
||||
hydrate();
|
||||
|
||||
assert.htmlEqual(target.innerHTML, '<input type="text">\nfoo');
|
||||
}
|
||||
});
|
@ -0,0 +1,6 @@
|
||||
<script>
|
||||
let value = $state('');
|
||||
</script>
|
||||
|
||||
<input type="text" bind:value={value}>
|
||||
{value}
|
Loading…
Reference in new issue