Svelte 5: $Effect runes can trigger themselves. Is this intended or an issue? #11551
-
TLDR: Effect runes seem to be able to trigger themselves creating infinite loops. This is different to equivalent Svelte 4 code and seems like a useless foot gun. Just checking if it is the intended behaviour? Hi All, I was having an issue where the $effect rune was causing an effect_update_depth_exceeded. I found the issue (eventually), I have massively simplified the code to recreate the issue and shown it below.
Can you see the issue? Looking at the code, the issue makes sense. Changing (I am very aware that issue goes away by a very simple refactoring of the code shown. Note I am not trying to ask how to fix this issue but trying to make sure people are aware of it existence and checking whether the effect is intended) The purpose of this post is I want to make sure that effects being able to rerun themselves is a conscious design decision and not a bug or unconsidered edge case of using the new $effect rune. Things that make me think this might not be the desired behaviour are the following:
My questions for the community are the following:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
This is intended. You generally should avoid setting Not every |
Beta Was this translation helpful? Give feedback.
This is intended.
You generally should avoid setting
$state
in an effect (as pointed out in the docs).Not every
$:
is an effect, many should become$derived
instead.