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

Cannot assign to derived state #214

Closed
didier opened this issue Feb 11, 2025 · 6 comments
Closed

Cannot assign to derived state #214

didier opened this issue Feb 11, 2025 · 6 comments

Comments

@didier
Copy link

didier commented Feb 11, 2025

Describe the bug

Just importing anything from Formsnap breaks the Vite dev server due to assigning to a constant.

I did a fresh npm install and it started appearing, but I was already on v2.0.0 before, so I'm not sure what changed now.

✘ [ERROR] node_modules/.pnpm/formsnap@2.0.0_svelte@5.19.10_sveltekit-superforms@2.23.1_@sveltejs+kit@2.17.1_@sveltej_987bc4fecae302b24a2f444f97bc821a/node_modules/formsnap/dist/formsnap.svelte.js:27:8 Cannot assign to derived state
https://svelte.dev/e/constant_assignment [plugin vite-plugin-svelte-module:optimize-svelte]

    node_modules/.pnpm/formsnap@2.0.0_svelte@5.19.10_sveltekit-superforms@2.23.1_@sveltejs+kit@2.17.1_@sveltej_987bc4fecae302b24a2f444f97bc821a/node_modules/formsnap/dist/formsnap.svelte.js:27:8:
      27 │        this.#name = props.name;
         ╵         ^

  The plugin "vite-plugin-svelte-module:optimize-svelte" was triggered by this import

    node_modules/.pnpm/formsnap@2.0.0_svelte@5.19.10_sveltekit-superforms@2.23.1_@sveltejs+kit@2.17.1_@sveltej_987bc4fecae302b24a2f444f97bc821a/node_modules/formsnap/dist/index.js:1:75:
      1 │ export { useFormField, useFormControl, getFormField, getFormControl } from "./formsnap.svelte.js";~~~~~~~~~~~~~~~~~~~~~~

Reproduction

https://stackblitz.com/edit/sveltejs-kit-template-default-2bpq2kq9?file=src%2Froutes%2F%2Bpage.svelte

System Info

See Stackblitz repro.

Severity

blocking all usage of Formsnap

@zachstence
Copy link

If you pin svelte to 5.19.9 the problem is fixed. svelte@5.19.10 was just released 2 hours ago, seems to have caused this somehow.

https://stackblitz.com/edit/sveltejs-kit-template-default-bekldygt?file=package.json

@zachstence
Copy link

Looks like this was an expected change in Svelte with this PR
sveltejs/svelte#15228

@huntabyte
Copy link
Member

I will investigate further but this seems like a bug with Svelte, as that line it is highlighting as assigning to derived state is not assigning to derived state.

@huntabyte huntabyte changed the title BREAKING: Cannot assign to derived state Cannot assign to derived state Feb 12, 2025
@huntabyte
Copy link
Member

This was a bug introduced by Svelte. There appears to be a fix PR submitted already so let's hope it gets merged/released soon :) sveltejs/svelte#15276

@dimfeld
Copy link

dimfeld commented Feb 12, 2025

Svelte 5.20 was just released with the above-mentioned PR. I just upgraded my code to it and don't see the error anymore so I think we're good here!

@huntabyte
Copy link
Member

Awesome, thanks for the update @dimfeld !

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

4 participants