-
-
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
A bindable array-type prop that uses a non-array prop to build its default value results in non-reactivity for the bindable property #11425
Comments
The problem is not even |
Even worst, it's actually every "complex" prop like objects or array. It's treated as immutable. |
I'll try to investigate a bit further later but in the meantime i'll send my findings: by being The fact that svelte treat this as immutable also mean that trying to modify a prop deeply will not work because the equality fn will just involve the top level. |
Behavior in Svelte 4 |
If you're not using the fallback value and instead pass something bound in, the value is reactive - playground example. So I think maybe we should proxify the default value? On the other hand, if you pass in |
But also it's a byproduct of every prop being On the other hand it does seems a bit of a smell. What if you could also use <script>
let { value: $state([0]), other_value: $state.frozen([0]), min: 0 } = $props();
</script> |
On discord another example was brought up where it's completely unexpected that a prop is frozen.
You can pass a non-reactive object and reactivity won't work either. Knowing that props are reactive, I'd expect the fallback value also to be reactive in a regular way ($state). Otherwise, it must be documented, and a way to change this behaviour must be provided. |
If a property is mutated, the assumption is that it is deeply reactive. In those cases, the fallback value should be proxified so that it also is deeply reactive. fixes #11425
If a property is mutated, the assumption is that it is deeply reactive. In those cases, the fallback value should be proxified so that it also is deeply reactive. fixes #11425
Describe the bug
Results in value not being reactive
Reproduction
https://svelte-5-preview.vercel.app/#H4sIAAAAAAAACkWOQarDMAxEryJEFykY6m7z40LPEWfhJmoRxIqxndIScvePsulu9AbNzIZPnqlg228oIRK2eE8JDdZv0qO8aa6EBsuy5lFJV8bMqd68-DpThS2ygANrIIYPOLhaa-Ad5pXAwenBMoXHTE0fWYbzrizlJZXm_KcJJ5aSaKzN8aGsu_wKpEtHz3a4vR129ZV1LGmtoCudxxzkRR4hsjiPVlX4OI9Xq1o3tEeC-wVdbmgwLhM_mSZsa15pH_Z_rDIG3w8BAAA=
Logs
No response
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: