-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
state_referenced_locally warning when trying to store an initial value #12877
Comments
Then you can just ignore the warning :) |
Well this is what I am doing actually... It's unclear especially here : const initialValue = $state.snapshot(field.value) It's obvious that I don't want any update as it is a snapshot... Maybe I missed something... is there a better way to break reactivity on purpose ? I mean without warning... |
If it won't change, surely it makes little sense to make it The warning is that you're doing something a little 'odd' that may not be what you intended, by giving mixed signals (pun intended) that the value is both a constant and reactive. |
It's a warning and not an error exactly because we can't know if your implementation is correct. We warn you so that if you are sure it's fine you can ignore that warning.
If I do something like this $effect(()=>{
console.log($state.snapshot(field.value));
}); I will actually log every time let initialValue = field.value;
You can do all sort of things but...why? Just ignore the warning leaving a comment for your future self. |
Describe the bug
Not sure if i am using runes as it should be, but I get :
State referenced in its own scope will never update. Did you mean to reference it inside a closure? (state_referenced_locally)
when trying to store an initial value from a stateI know
initialValue
won't change and this is what I am expectedWhat am I doing wrong ?
Reproduction
https://svelte-5-preview.vercel.app/#H4sIAAAAAAAAE41UbYucMBD-K4MU1MPT9lvxVCgHhbb0hRb6Zfc-ZHXcCxcTScbrbcX_XpLo6W6P0l12yGaePDN5ZiZj0HKBJsh3YyBZh0EevOv7IAno1Ns_5hEFYZAERg26tjuFqTXvqdrLPfGuV5rgg5SoodWqgzDN3L_UHwwtyv5qJQ3BA54MlLALWZhAeLCmtqaxBq1pw7sVfkT6zmSjuk94ghKiGMrKcew-M7pPW6GUjtxSO1gUw5XzpwLlke7ju70EsHwCCXpG91DCK0OMMNpyR3F8nmd9z-QRv_kDPuzoEDSTnJ-2rskzFNkqjywOA5GSoGQteP1QjivvVPm1y6rIPLAqDjqr9rLwglpXOVo7QVYFSdCphrccmyAnPeCUPJfM4f-3aP6Ko9djsor0WvXGXUPuKbu6gut_f7wUtxoZ4Xulux9WUeAGWE0DE-IErdIdMAn4RKglE2C7LAF8yp1r7o6UjKvOVWZtO8iauJJQXxBHsVXfF9KXslH1WskRWA6hkrZ_DjmE9EuFCdR5SBrtXpOHrRp0mADmYcsf7V6bh4Y_hVN840mtBfDKDAbfcxSNLb3VaC0_AIBGGrRc2sF-DRI8MjFg5Gy8ce2pUfXOktxB6UGrc0oWTrD9NHPEa6hNuGeam9U5Lctp3pzOLnOZ6NHrFm3zW9mXvTWpRYZkS-7tSy0Cvohrg7kWKC-L6YdlRswqv2pQ80dsItcaS1yv_QbOJSfOxE8rE5T-dLpquu0gJT_IfqDouRgbMJSAKTF9RFpPT5eTK9gBhb1DuQ-45doHlYucF5nz2TF1DuDNigEl3aoc5xQmX9Zy3GZvx9lF6avbQWuU8-OUg5_2Iusr5z27cg7nJDOqVg26uR4__vj6JTWkuTzy9uTVbFQdu8stMFkYOgmcX4IGZ4EabnrBTvlBqPph7qOO6SOX16T6_I3G7ub5mXMCLMoqSdeG_8YcXqdvF9jLhy_CrMK7jP5-4O6mP2Q2eaWfBgAA
Logs
No response
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: