Skip to content
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

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

Open
henrykrinkle01 opened this issue Dec 25, 2024 · 0 comments
Open

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

henrykrinkle01 opened this issue Dec 25, 2024 · 0 comments

Comments

@henrykrinkle01
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant