mirror of https://github.com/sveltejs/svelte
fix: support `$state.snapshot` as part of variable declarations (#11235)
fixes #11234pull/11244/head
parent
307f15d5f7
commit
cca67bba51
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"svelte": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: support `$state.snapshot` as part of variable declarations
|
@ -1,12 +1,12 @@
|
|||||||
import { test } from '../../test';
|
import { test } from '../../test';
|
||||||
|
|
||||||
export default test({
|
export default test({
|
||||||
html: `<button>[{"a":0}]</button>`,
|
html: `[{"a":0}] <button>[{"a":0}]</button>`,
|
||||||
|
|
||||||
async test({ assert, target }) {
|
async test({ assert, target }) {
|
||||||
const btn = target.querySelector('button');
|
const btn = target.querySelector('button');
|
||||||
|
|
||||||
await btn?.click();
|
await btn?.click();
|
||||||
assert.htmlEqual(target.innerHTML, `<button>[{"a":0},{"a":1}]</button>`);
|
assert.htmlEqual(target.innerHTML, `[{"a":0}] <button>[{"a":0},{"a":1}]</button>`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<script>
|
<script>
|
||||||
let items = $state([{a: 0}]);
|
let items = $state([{a: 0}]);
|
||||||
|
let start = $state.snapshot(items);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
{JSON.stringify(start)}
|
||||||
<button on:click={() => items.push({a: items.length})}>{JSON.stringify(structuredClone($state.snapshot(items)))}</button>
|
<button on:click={() => items.push({a: items.length})}>{JSON.stringify(structuredClone($state.snapshot(items)))}</button>
|
||||||
|
Loading…
Reference in new issue