svelte icon indicating copy to clipboard operation
svelte copied to clipboard

Svelte 5: `$derived` state mutation in function expressions does not error at compile time

Open navorite opened this issue 10 months ago • 1 comments

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

REPL

Logs

No response

System Info

N/A

Severity

annoyance

navorite avatar Apr 17 '24 15:04 navorite

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.

dummdidumm avatar Apr 29 '24 09:04 dummdidumm

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.

trueadm avatar May 10 '24 20:05 trueadm