mirror of https://github.com/sveltejs/svelte
fix: convert input value to number on hydration (#14349)
* convert input value to number on hydration * add test * changeset --------- Co-authored-by: Rich Harris <rich.harris@vercel.com>pull/14363/head
parent
b145035a00
commit
012166ec3c
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: coerce value to number when hydrating range/number input with changed value
|
@ -0,0 +1,17 @@
|
|||||||
|
import { flushSync } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
skip_mode: ['client'],
|
||||||
|
|
||||||
|
test({ assert, target, hydrate }) {
|
||||||
|
const input = /** @type {HTMLInputElement} */ (target.querySelector('input'));
|
||||||
|
input.value = '1';
|
||||||
|
input.dispatchEvent(new window.Event('input'));
|
||||||
|
// Hydration shouldn't reset the value to empty
|
||||||
|
hydrate();
|
||||||
|
flushSync();
|
||||||
|
|
||||||
|
assert.htmlEqual(target.innerHTML, '<input type="number">\n1 (number)');
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,6 @@
|
|||||||
|
<script>
|
||||||
|
let value = $state(0);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<input type="number" bind:value={value}>
|
||||||
|
{value} ({typeof value})
|
Loading…
Reference in new issue