-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Unexpected Reactive Updates #8895
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
Just in case there's an issue w/ the reproduction in the REPL, here's the export. |
Ran into this as well. Seems to be a duplicate of #4933. Undocumented behaviour intended to fix #2444, but causes surprising behaviour in some other cases and was marked as a bug. Workaround: Hide the dependencies from the compiler. In your REPL's $: bar = foo ? foo.clone() : new Example("default bar") you should do this instead (or make let bar;
function setBar(x) {
bar = x;
}
$: setBar(foo ? foo.clone() : new Example("default bar")); That way, the compiler won't know bar depends on foo and won't invalidate both when you modify bar. |
@mpopovic4116 Nice! I'd done something similar in my Workaround.svelte, but it depended on me knowing exactly where And thanks for the issue link. I'd done some searching but didn't find #4933. I think that fully captures this case, so I'll close this as a duplicate and watch the other. |
What is the meaning of |
Describe the bug
In a component, a reactive update like this:
Ends up causing reactivity to treat
foo
as updated when it hasn't been changed (and can not have been changed, since it's not passed/bound to any other components.)Is this a bug, or undocumented behavior?
These kinds of things are difficult to debug and eat a lot of time. There's not good visibility into why Svelte is choosing to act as if some value was updated.
Reproduction
REPL link: https://svelte.dev/repl/65a48991ca7b46218e67b933edca77b4?version=4.0.1
Logs
See logs in the REPL. 😊
System Info
Reproduced in the REPL with v4.0.1, and locally with 3.59.2.
Severity
annoyance
The text was updated successfully, but these errors were encountered: