-
-
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
Svelte 5: Confusing and unclear warning state_referenced_locally
#11883
Comments
The state will go out of sync on reassignment. E.g. let numbers = $state();
numbers = [1, 2, 3];
let obj = { a: numbers };
numbers = [4, 5, 6]; Now // no warning
let obj = { get a() { return numbers } }; |
@brunnerh Thanks, the reply explains this very well 👍. But the I don't think people can easily understand this warning, and there's no documentation or links to a more detailed explanation and examples. |
Documentation will likely come before the actual release but I do agree that the error is too technical...however I struggle to find better frasing that is not too long. Do you have some suggestion? I was thinking something on the line of "Using a state variable in the same scope is created can lead to out of sync...did you mean to reference it inside a closure?" |
Suffice to say, seeing that phrase, I never thought it referred to using a |
A getter is only a way to get it into a closure...having it in a function is fine too. I don't have ideas about how to change that specific sentence |
This comment was marked as off-topic.
This comment was marked as off-topic.
I really don't get why you are always so oppositive... I'm telling you I agree with you, I'm asking for your help and yet you think I'm joking on you. |
I think technical language accuracy is less important in this context, compared to the more important message that this warning is trying to get across. I suggest: "State referenced in its own scope will never update. If you intend to to keep this state in-sync, consider using a getter function or other forms of closure. (state_referenced_locally)". |
Describe the bug
What problem was this warning intended to avoid in the first place?
Why does it always appear in confusing and unclear places?
In the slightly modified official documentation example below, everything works fine and I don't understand what the warning means.
Possibly related issues: #9857 #10905
Reproduction
Svelte5-REPL
Logs
No response
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: