-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Closed
Description
Describe the bug
In Svelte 4, it's possible to do:
<script>
let n = 0;
$: func = () => n;
$: func, console.log('func changed'); // Effect runs when n changes
</script>
<button on:click={() => n++}>Click</button>
The runes equivalent does not work:
<script>
let n = $state(0);
let func = $derived(() => n);
$effect(() => {
func, console.log('func changed'); // Effect does not run when n changes
});
</script>
<button onclick={() => n++}>Click</button>
If func is called within the $effect callback, the effect runs. When it is only referenced, the effect does not run.
Reproduction
Logs
No response
System Info
System:
OS: macOS 14.7
CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
Memory: 361.81 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.13.1 - ~/.nvm/versions/node/v20.13.1/bin/node
Yarn: 1.22.22 - ~/.nvm/versions/node/v20.13.1/bin/yarn
npm: 10.5.2 - ~/.nvm/versions/node/v20.13.1/bin/npm
pnpm: 9.11.0 - ~/.nvm/versions/node/v20.13.1/bin/pnpm
Browsers:
Brave Browser: 100.1.37.111
Chrome: 128.0.6613.139
Chrome Canary: 131.0.6728.0
Safari: 18.0
npmPackages:
svelte: ^5.0.0-next.251 => 5.0.0-next.251Severity
blocking an upgrade
Metadata
Metadata
Assignees
Labels
No labels