-
-
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
Cannot change $:-computed variable when it is computed from props #7574
Comments
Line 125 of the generated code contains See #7416 (comment) |
@gtm-nayan it's a known issue then. We stumble upon it from time to time in our projects and it's quite frustrating. Svelte otherwise has an easy way to explain the reactivity - "if the compiler sees a read, it will re-run the code on change", and "this only happens on some variable assignment". But in this case, there is no obvious reason that I think this wasn't an issue a while ago when I started using Svelte 3. Do we really need Svelte 4 to fix this obviously bad behavior? |
This comes down to
Svelte 5 fixes this by separating these into two distinct runes, Furthermore, due to fine-grained reactivity possibilities in Svelte 5, you can now write the state such that the binding will not update the whole array. |
Describe the bug
$: expression should track source variables and execute only when they change.
This works with local component state, but not when the state is passed to another component.
This is a consistency and developer usability issue. As a developer, I expect exported variables to work exactly the same as internal ones, especially if they are not bound in parent. As a result, a lot of "strange" code needs to be written to workaround the issue.
Reproduction
https://svelte.dev/repl/1d4698e72d614e0e96450b52c33f8665?version=3.48.0
Logs
No response
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: