-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
[BUG] Dependence of reactivity on the order of declaration #5525
Comments
duplicate #4516 |
I wouldn't be so sure. To be clear: without function all works fine ↓ |
yep my bad, it works as expected then, the compiler will try to re-order the executing order of declarations depending on each other ( so in the second screenshot, You can check the executing order under the |
Indeed, this is the expected behavior. When the compiler sorts reactive declarations/blocks according to dependencies, it only looks at variables referenced and assigned to within the block itself. This lets you specifically 'hide' references and updates from the compiler, and also makes the whole ordering process much more feasible. |
@Conduitry no is not. Is surprising behavior. |
@Conduitry I'm not sure, but I think you didn't catch the whole problem described by example. Perhaps, because this example doesn't fully reflect the problem and concentrates on unnecessary things. Let's say, we've a much cleaner example: <script>
let foo = 0,
bar = 0;
$: bar, alert();
$: foo, func();
function func() {
bar += 2;
}
</script>
{foo} {bar}
<button on:click={e => ++foo}>
Increment
</button> The I know why it's happening, but is it really not a problem? @Rich-Harris |
Reactive statement declaration through $: label before the second reactive statement that changes the first one through function is not reactive;
REPL: https://ru.svelte.dev/repl/7a9593fcd21848f7bdac90bd93fb2f9e?version=3.29.0
The text was updated successfully, but these errors were encountered: