Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
navorite opened this issue Apr 17, 2024 · 2 comments
Milestone

Comments

@navorite
Copy link
Contributor

navorite commented Apr 17, 2024

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 navorite changed the title Svelte 5: State mutation in function expressions is not checked at compile time Svelte 5: State mutation in $derived function expressions is not checked at compile time Apr 17, 2024
@navorite navorite changed the title Svelte 5: State mutation in $derived function expressions is not checked at compile time Svelte 5: $derived state mutation in function expressions does not error at compile time Apr 17, 2024
@Rich-Harris Rich-Harris added this to the 5.0 milestone Apr 21, 2024
@dummdidumm
Copy link
Member

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.

@trueadm
Copy link
Contributor

trueadm commented May 10, 2024

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 trueadm closed this as completed May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants