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

Svelecte mutates values passed without bind #228

Closed
jamesst20 opened this issue May 16, 2024 · 0 comments
Closed

Svelecte mutates values passed without bind #228

jamesst20 opened this issue May 16, 2024 · 0 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@jamesst20
Copy link

jamesst20 commented May 16, 2024

Error

[svelte] ownership_invalid_mutation node_modules/.pnpm/svelecte@5.0.0-next.4_svelte@5.0.0-
next.135/node_modules/svelecte/dist/Svelecte.svelte mutated a value owned by ...FormSelectBuilder.svelte. 
This is strongly discouraged. Consider passing values to child components with `bind:`, or use a callback instead

Demo

Capture d’écran, le 2024-05-16 à 15 12 44

I have a component that can build options passed to Svelecte.

Sample code

<FormSelectBuilder bind:value={field.choices} multiple={!!field.multiple} />
<FormSelect
        bind:value={field.choicesDefault}
        options={field.choices}
        label={"Default value(s)"}
        multiple={field.multiple}
      />
 <FormToggle bind:value={field.multiple} label={"Multiple"} />

Problem

It seems that as soon as I select an item in Svelecte (FormSelect), Svelecte mutates the field.choices[i] I have selected.

I believe this happens because it sets $selected: true to that option.

@mskocik mskocik added the bug Something isn't working label May 17, 2024
@mskocik mskocik self-assigned this May 17, 2024
@mskocik mskocik added this to the v5.0 milestone May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants