mirror of https://github.com/sveltejs/svelte
fix: keep `$state.eager` when used as a variable initializer (#18809)
fixes #18808 If you write `let x = $state.eager(...)`, the client compiler used to delete that line and then still read `x`. The page crashed with `x is not defined`. Server rendering kept the binding. Using `$state.eager(...)` directly in the markup already worked. This puts the `let` / `const` form on the same path as `$state.snapshot`. Added a runtime-runes sample that fails without this change. Co-authored-by: Xia Chao <236466140+bun-unsafe@users.noreply.github.com>pull/17600/merge
parent
ce89035ecb
commit
34b13ac3e4
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: keep `$state.eager` when used as a variable initializer
|
||||
@ -0,0 +1,5 @@
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
html: `<p>20</p>`
|
||||
});
|
||||
@ -0,0 +1,7 @@
|
||||
<script>
|
||||
let n = $state(2);
|
||||
let d = $derived(n * 10);
|
||||
let x = $state.eager(d);
|
||||
</script>
|
||||
|
||||
<p>{x}</p>
|
||||
Loading…
Reference in new issue