-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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 does not call action update method when mutating arrays #10460
Comments
Update: I can get around this by using |
It looks like actions only update when their parameter gets reassigned. That seems to be consistent with svelte 4, but I'm not entirely sure whether that is entirely intended in either svelte version |
@MotionlessTrain in svelte 4 reactivity is only triggered on reassignment so this is expected |
This is the expected behaviour. Svelte's reactivity is fine-grain, so changing a property of an object passed to a parameter will not cause it to update to action. You can use |
While it's explainable why this happens, this is still very surprising to someone migrating their code. Moreover, just putting |
@dummdidumm I personally feel that doing so will open up pandoras box. I also don't think there should be an expectation that things should be the same in runes mode. I definitely wouldn't want the behaviour that my action would update every time something pushes a new entry to my array. |
But that's the contract of the current action API - call update when something changes within that object. We could make it so that when you're not returning |
Or maybe update is not needed anymore in actions, it could be based on |
I agree, effects are cleaner than the update and destroy methods. |
then what is |
This issue highlights that that the "all or nothing" approach of the action parameter is not state of the art and does not "feel Svelte" in so many ways. Svelte 5 would be the chance to deprecate it and rework actions to make them more reactive and surgical. I want to use this opportunity to point towards sveltejs/rfcs#41 again. Manually tracking changes in the parameter and juggling things like
But now my action can only handle |
Ensure update methods of actions and reactive statements work with fine-grained `$state` by deep-reading them. This is necessary because mutations to `$state` objects don't notify listeners to only the object as a whole, it only notifies the listeners of the property that changed. fixes #10460 fixes simeydotme/svelte-range-slider-pips#130
@Prinzhorn oh wow that’s actually an interesting RFC would be pretty interesting seeing how that can be updated with the new Svelte 5 conventions especially surrounding props and callback functions instead of event dispatchers |
Ensure update methods of actions and reactive statements work with fine-grained `$state` by deep-reading them. This is necessary because mutations to `$state` objects don't notify listeners to only the object as a whole, it only notifies the listeners of the property that changed. fixes #10460 fixes simeydotme/svelte-range-slider-pips#130
Describe the bug
In this component
I only see logs when using the old way of assignment reactivity, since we can use
push
now I expected this to work in actions too, it seems like it doesn'tReproduction
https://svelte-5-preview.vercel.app/#H4sIAAAAAAAAE41SQW-0IBD9KxO-JtXEuHfrmvTYU489rHugMu6SKhgYN90Y_nsDaHW3TfNBoo_hzbzHwMRa2aFlxWFiivfICvY8DCxjdB38wl6wI2QZs3o0jY-UtjFyoKpWNXVIIAl7C3t4sMQJk8MxrZXfa0fVkNQKDJ6kJTQvhH3i2enk92tqtLK6w7zTpxj3YRez8XPQhuC7CA-_RGmBWZRMYaoVAED8GqTRqCXmxzgITlgsBiuYZePcij-eNM30x3Qt4EerDSSeGw8Kup3Vb4r5-fOYtwy3FnbZigVaMvpaQJLOHrfym5wI3VOt3F2DuRBBdPEUDObDaM9JhB2qE5237b3Pfe3EG7_eVoA9HPI8D3ju-VzpuFTaXnKvL_ibDT0ki3K5W9-OKt9HIq1Aq6LpZPOxn2YvruJCBL1yFznVH-zo_D9zVpeuivg-p1bTP-TNeX413AYQzloKeammsCx3HvvgtPPs0FW_D6PFIr7VfaBaV0Uyy1ivhWwlClaQGdEd3RdyNdiBfQMAAA==
Logs
No response
System Info
Severity
blocking an upgrade
The text was updated successfully, but these errors were encountered: