-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Bug with reactive assignments and their relative positions #3361
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
Svelte does try to reorder reactive statements according to their dependencies, but it can only look at the variables it can statically see as part of the The instrumented <script>
let a = 0;
function f() {
a++;
}
$: f(a);
</script>
{a} This doesn't currently cause an infinite loop, but it seems like it would have to in order to support something like what this issue is asking for. My inclination is that the current behavior it something that should simply be documented better. We don't currently have a good place for these slightly deeper dives to live. |
@Conduitry "This doesn't currently cause an infinite loop" |
Closing for now, as I think we now have a reasonable place to document this and a pointer to do so, should somebody feel inclined. |
Describe the bug
If a component prop
foo
is modified by a reactive statement, and another propertybar
is intended to be reactively set whenfoo
changes, then whether or not thebar
assignment runs or not can depend on its relative position to thefoo
statement within the source code.To Reproduce
REPL: https://svelte.dev/repl/ada3812c534f48b5ace26933f31fdaaf?version=3.7.1
(Obviously there are more suitable/effective patterns that could be used to implement this trivial example, but it's intent is only to distill what I encountered in a more complicated scenario.)
Expected behavior
I would expect the reactive assignments to fire consistently, regardless of their relative placement to the other statements.
Severity
Now knowing the workaround, this isn't severe -- but for any newcomers that might trip over this, (especially since the underlying cause is very subtle) it can prove quite maddening.
The text was updated successfully, but these errors were encountered: