mskocik / svelecte

Flexible autocomplete/select component written in Svelte,
https://svelecte.vercel.app
MIT License
472 stars 44 forks source link

Svelecte: Unexpected mutation on a specific scenario #230

Open jamesst20 opened 6 months ago

jamesst20 commented 6 months ago

Hi,

version next.6 did fix many mutation warnings I had, however there is still one instance that I have the warning and it's when

<Svelecte
   ...
   value={...}
   valueAsObject={true}
   strictMode={false}
   onChange={...}

It happens on page load and on value change with these exact parameters. Note: bind is not used on value

I believe the source is here: https://github.com/mskocik/svelecte/blob/master/src/lib/Svelecte.svelte#L473 but I didn't check for sure

jamesst20 commented 6 months ago

I've got another case scenario

  let testVal = $state([]);
  let testOptions = [
    { text: "Test 1", value: "test-1" },
  ]

  <Svelecte
    bind:value={testVal}
    options={testOptions}
    multiple={true}
  />

It happens when I select an item

mskocik commented 6 months ago

I am afraid this can't be solved right now. I suspect this can be some kind of svelte v4-v5 interoperability bug 🤔

The bad news is that for fix whole lib needs to be rewritten, good news (for now) is, that it's just a warning and doesn't break anything.

mskocik commented 6 months ago

Because in principle this REPL works the same way... So I don't really understand.

jamesst20 commented 6 months ago

Because in principle this REPL works the same way... So I don't really understand.

This would be a more honest representation of what is going on: REPL

Svelte 5 is now able to deeply react to deep nested changes including array#push, slice, etc. without doing any kind of copy, deep clone, etc.

With this capacity, it's able to ensure a component that receives a value is never mutated from within that component unless it receives the value using bind:

Right now I don't see any way to tell if a variable has been passed using bind or not. It doesn't appear documented either. I think I will open an issue at svelte

mskocik commented 6 months ago

Right now I don't see any way to tell if a variable has been passed using bind or not. It doesn't appear documented either. I think I will open an issue at svelte

👍 Yes, I came to the same conclusion, that it's impossible to find out.

Your example is definitely better, but Svelecte has the same problem also with 'single' item value, but maybe that's because of mix rune and non-rune mode.

jamesst20 commented 6 months ago

Right now I don't see any way to tell if a variable has been passed using bind or not. It doesn't appear documented either. I think I will open an issue at svelte

👍 Yes, I came to the same conclusion, that it's impossible to find out.

Your example is definitely better, but Svelecte has the same problem also with 'single' item value, but maybe that's because of mix rune and non-rune mode.

I have opened an issue at Svelte in case you want to follow: https://github.com/sveltejs/svelte/issues/11672