The data
prop in +page.svelte
and +layout.svelte
is no longer reactive after migrating to svelte 5
#12999
Labels
data
prop in +page.svelte
and +layout.svelte
is no longer reactive after migrating to svelte 5
#12999
Describe the bug
$effect
is discouraged, yet it is the only viable solution for handling updates that come from both the client and server. This is neither mentioned nor explained in the migration or core documentation.Suggestions
$effect
is appropriateStep 1 - Svelte 4 Reactivity
This is a typical reactive setup with local state update for optimistic UI.
Step 2 - Migrate to svelte 5 via
npx sv migrate svelte-5
The CLI replaced
export let
with$props
, but we're no longer able to get reactive updates fordata.value
.$bindable()
was also added for no observable effect.Step 3 - Use
$state
Local updates now work, but we're no longer able to receive updates from the server.
Step 3.1 - Use
$derived
Cannot assign to derived state
. :|Step 3.2 - Use
$state
+$effect
Finally, we're able to return to the svelte 4 behaviour. This is also the solution @benmccann suggests in #12902 (comment). But this solution is a problem, as he puts it.
On top of that step 3 and 3.1 were intuitive solutions a user will reach for, yet it is incorrect.
Severity
blocking an upgrade
Additional Information
Global State
I think there is also a high correlation between this and setting up a global state, as users often will and are encouraged to set up their data in the load fn and would like to use them in various pages. I created a second issue that addresses that in #13000.
Related discussions from maintainers
$props()
#12902Related help threads
The text was updated successfully, but these errors were encountered: