-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
UI not re-rendering when rune is updated #9301
Comments
A kind user on the Svelte discord did some quick analysis of the compiler output: |
That's neat, and I'm surprised that works? (makes it definitely feel like current behaviour is a bug). But I need shared exported app-wide state so that doesn't work for me. |
Seems to be a bug? maybe in future will be fixed |
It was slightly mentioned in another issue that runes are bound to component lifecycle. So the problem isn't that the Something should be done about this, otherwise this small nuance will drive people crazy. |
That's awesome i will take this as note for future to manage global states @7nik i don't think this is a problem. It makes people investigate some coding patterns... I imagine more later it will exist a video, issue or forum that mentionate it, Svelte has extensive docs and a lovely community |
If that were the problem, wouldn't this example also break? |
let's investigate deeper: as was mentioned on discord, runes use different methods of comparing the new and old values, which are set once at their creation: const context = current_component_context;
if (context && !context.immutable) {
return safe_equal;
}
return default_equals; Where Numbers are primitive, and their change gets detected correctly by both methods. But mutation of object/array isn't detected at all. Instead, there is still gets added a trigger on assignment, and if So, the issue narrows down to the reactivity of mutation on a global object created not during a component initialization. (and probably some other lifecycle events). |
So I definitely understand that |
ideally |
@7nik maybe we should back to the idea with |
But the issue is with the value mutation: a comparator (equalentor) will receive in The logic of choosing between |
given that the actual function used to create these runes accepts an equality function as the second argument I would've expected |
A new comparison method is definitely needed |
@Thiagolino8 |
|
@Thiagolino8 |
Not really, his version is a singleton because it always returns the same instance, your version always creates a new instance |
Oh yeah so we cannot share the instances btw components when we just import the |
This is fixed now as a result of #9739 being merged! 🎉 |
Describe the bug
So I'm not 100% sure if this is a bug with runes, but it sure feels like one.
In the example below I have a
$state
rune in a Svelte component, and a$state
rune in a JS file. Both are arrays, and I'm pushing values into the array and doing the oldlist = list
trick to trigger an update. This works in the component, but not in the one imported from the JS file. The problem goes away if I uses a spread operator (list = [...list]
), but I'd rather reuse the same array to reduce GC pressure (And I also have a considerable amount of code that mutates arrays rather than reallocating. It would be a pain to change it all).Additionally, is my
other
export from the JS file 'idiomatic' for global state using runes? Is there a more rune-idiomatic way of writing what I have?Reproduction
Edit: updated
other.js
->other.svelte.js
https://svelte-5-preview.vercel.app/#H4sIAAAAAAAACp2SsW7bMBCGX-XAFrAMGNLuyCqCdMmQMehgeVCks8WY4gkkFTcQNOYNOhbo0ifrE-QRehQVx0DcBsgiisf_7n4ev15spUIrlute6KJBsRSXbSsWwj22fmMfUDnkvaXOlD6S2tLI1mW5zp1sWjIOeiBXo4EBtoYayEWcjIE4ZMf3NhcXrOcMhQ6UtA5W8Nm6wmG0zkUtc7GZT4qSNB-3na1ZE81hlUHv45zLebE_iELKmDHFWeuXKeJrkMJY0S7y4aAc-Jsmr_Z1etc5RxpIL0sly_2q99WH7LKqYFbLGTiCkviOGvVkO7ryQrjBeZqEbK6U2rbQ2Tcyewt_fj5xD7_nOKlxTP0nLMo6FCgsr0OwmSqZ9bxLE_7hgJcmXjp4oyH5jMkw21OrqBSNbsM7vOf0K6HVMwcHdvzl-dfvH_9yHDp9xDcT01AltxIrsXSmw2FxBOyUjVfS7u0pZec58fc8ooLfR_gCL-Hiq4DK7iWZ8enBoOuMDnjAsPCCEaL5Wa5CiwAMwFu0kgRuNUPRMBJS74D7wh0qOrBII3RtxWbtGL69XgBPHq550J2qWLBH_0gV8bG0cJCuJj4vFemXUoUxxeOx09R-HcfjI2z-S3euPeBvB78Z_gJmEFQX5QMAAA==
Logs
No response
System Info
Severity
blocking an upgrade
The text was updated successfully, but these errors were encountered: