You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It was my understanding that ordering of reactivity statements should not matter, as the svelte compiler ought to figure it out. If this is expected behavior, a warning (akin to circular dependency detection) would be much appreciated.
I spent numerous hours hounding down a reactivity issue, ruling out numerous other options before realizing it was this ordering issue. I am concerned that this will happened again and cause similar head scratching for my teammates or, worse, let subtle bugs hit production.
*RE: issue 5365 - Looking at the replies, it seems to share the same behavior & cause; but since it was done with an older version of svelte and was using stores, I was not sure if I should've replied there. To maintainers: please move this issue as seen fit
This is intended. Apart from the stores in the issue you mentioned, most everything else is relevant. See also #3361, #5190, #5905, probably others.
The reactive blocks are ordered via simple static analysis at compile time, and all the compiler looks at are the variables that are assigned to and used within the block itself, not in any functions called by them.
My comment in #5848 goes into a bit of detail about how this works.
Gotcha - thank you for the response and appreciate linking the prior issues. Knowing that the svelte compiler only looks at the variables in the reactive statement (and does not dive into the function) is very insightful. I'll let my dev team to be vigilant for that situation.
Describe the bug
Potentially related?* #5365
Consider this:
vs this:
Same code, only different order - however the first one is broken while the latter works; see this REPL: https://svelte.dev/repl/9d8cd5bb47164f96a19d1d887662a06b?version=3.48.0
It was my understanding that ordering of reactivity statements should not matter, as the svelte compiler ought to figure it out. If this is expected behavior, a warning (akin to circular dependency detection) would be much appreciated.
I spent numerous hours hounding down a reactivity issue, ruling out numerous other options before realizing it was this ordering issue. I am concerned that this will happened again and cause similar head scratching for my teammates or, worse, let subtle bugs hit production.
*RE: issue 5365 - Looking at the replies, it seems to share the same behavior & cause; but since it was done with an older version of svelte and was using stores, I was not sure if I should've replied there. To maintainers: please move this issue as seen fit
Reproduction
https://svelte.dev/repl/9d8cd5bb47164f96a19d1d887662a06b?version=3.48.0
Logs
No response
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: