-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Svelte 5: Document when not to use $effect
#10193
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
Comments
In that regard, I don't know if it's more a Kit issue than a Svelte issue, but since it came up on Discord: The docs should also make clear that These are not the same: <script>
let a = 1
let b = 2
$: c = a + b
</script>
{c} // server responds with c == 3 <script>
let a = $state(1)
let b = $state(2)
let c = $state(0)
$effect(() => {
c = a + b
})
</script>
{c} // server responds with c == 0, then updates the DOM on mount (--> flicker, SEO, etc) |
I sent a PR for this awhile back that's fallen a bit down the queue: #9940 |
Describe the problem
People tend to overuse
$effect
. We should make it clear in the documentation when to actually use it, and when to use other things instead.This doesn't need to be on the preview docs but should certainly be part of the final docs.
Describe the proposed solution
If we have a more general guide for runes, describe how to ensure reactivity in various ways and try to avoid mentioning
$effect
as much as possible.In the API section, within
$effect
, start by saying that you likely don't need$effect
:$derived
$derived
"), use an object with getters and setters instead (no glitches/dangers of infinite loops, works in SSR)Importance
would make my life easier
The text was updated successfully, but these errors were encountered: