svelte
svelte copied to clipboard
Svelte 5: `$derived` state mutation in function expressions does not error at compile time
Describe the bug
Currently, state mutation inside derived runes is not detected at compile time if a function expression is used e.g. $dervied.by
or $dervied
with an IIFE. Instead, if you increase the count to 5, you'll see the error at runtime. This is not ideal.
Reproduction
Logs
No response
System Info
N/A
Severity
annoyance
I don't think it's worth it tackling this. We will only be able to catch the simplest of cases and the additional code to detect these cases will bloat the compiler code.
Yeah we definitely won't be doing this statically. It will give people a false hope that extracting logic into another function will fix their problem.