-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Is this a bug or is this a feature of Svelte reactivity statements? #7749
Comments
Even if you remove the button, you get two logs, which is the original bug. Svelte triggers updates for no reason when binding objects. |
|
Can you elaborate and provide a REPL? You"re saying you see unnecessary updates without using |
Please, |
Thanks, this looks like a different bug to me (there might already be a duplicate issue though). For some reason Svelte invalidates the expression used in the condition. If you do this: - $: if (data) {
+ $: if (true) {
console.log("--- WTF-Trigger---");
dataNew = [{key: 1, val: "1"}];
} then nothing is logged. Which doesn"t make sense, because |
Seems closely related to this #7129 (comment) |
Interesting, with a primitive attributes does nothing going on like this. Looks like a hidden linking (bounding) under the hood, that causes Svelte to track passed arguments as a single object. And what is even more interesting is that if we change in the click handler to the SAME assignment (even though the value of the ENTIRE object "data" also changes), but the object is not itself, the problem also disappears. |
In case it might be useful: here"s another eample where this issue manifests itself:
According to a comment on the linked stackoverlow question, this bug seems to have been introduced after the Edit: the bug can be reproduced with |
This will be fixed in Svelte 5 through tracking dependencies more correctly at runtime |
Describe the bug
App.svelte:
Child.svelte:
Output on button click:
Related StackOverflow
It seems that this only happens when passing (binding) a non primitive values (objects, arrays).
The data of "data" not changed, why both statements have been triggered in Child.svelte component?
Looks like a bug...
Reproduction
https://svelte.dev/repl/87031a5efc554b7fba7ea177b6b30b81?version=3.49.0
Logs
No response
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: