Skip to content

Broken tutorial due to data being immutable in Svelte 5 #1069

Closed
@henrykrinkle01

Description

@henrykrinkle01

Today somebody in the Discord server asked why the UI doesn't update with the official solution:

https://svelte.dev/tutorial/kit/post-handlers

The solution worked in Svelte 4 because the data props was mutable. In Svelte 5 it's no longer the case. This issue has been brought up several times:
#12999
#14536

I assume that the tutorial is migrated from Svelte 4 using the migration tool which just changes export let data to let { data = $bindable() } = $props() which currently does nothing.

I offered this answer:

    let { data: _data } = $props();
    let data = $state(_data);
    $effect(() => {
        data = _data;
    });

However, is this pattern really what should be put into the official tutorial to teach new people about Svelte/Kit?

To my understanding, there are 3 possible solutions:

  • Do nothing, just use $effect, which I only consider as a workaround.
  • Make data = $bindable() work, which should make data and page.data mutable for optimistic UI updates. Best solution IMO. It worked in Svelte 4 so why can't it work in Svelte 5?
  • Something else like $state.link.

So what should be done about this tutorial in particular and the underlying problem in general?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions