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

bind inside #each block on destructured value #6860

Closed
aMediocreDad opened this issue Oct 19, 2021 · 3 comments · Fixed by #7526
Closed

bind inside #each block on destructured value #6860

aMediocreDad opened this issue Oct 19, 2021 · 3 comments · Fixed by #7526

Comments

@aMediocreDad
Copy link
Contributor

aMediocreDad commented Oct 19, 2021

Describe the bug

When using destructuring with spread syntax in an #each block (keyed or not):

{#each objArray as {id, ...rest} (id)}
	<input bind:value={rest[someProperty]} />
{/each}

The bind fails, and e.g. what you type will be rejected (the value does not update).

Not using destructuring works as expected:

{#each objArray as data (data.id)}
	<input bind:value={data[someProperty]} />
{/each}

Edit:

Strangely, while testing I noticed that nested values within a rest element functions as expected:

{#each objArray as {id, ...rest} (id)}
	<input bind:value={rest.bar.someProperty} />
{/each}

Reproduction

https://svelte.dev/repl/761103ad2e254ee0a95454fc82c314c7?version=3.44.0

Logs

No errors output.

System Info

# Tested on FireFox (Win/macOS), Chrome (Win/macOS), and iOS webkit in REPL. 

System:
    OS: Windows 10 10.0.22000
    CPU: (8) x64 Intel(R) Core(TM) i7-9700K CPU @ 3.60GHz
    Memory: 19.86 GB / 31.92 GB
  Binaries:
    Node: 14.17.5 - C:\Program Files\nodejs\node.EXE
    npm: 7.20.6 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 94.0.4606.81
    Edge: Spartan (44.22000.120.0), Chromium (94.0.992.50)
    Internet Explorer: 11.0.22000.120

Severity

annoyance

@RaiVaibhav
Copy link
Contributor

seems like the input value change not changing the objArray because of the runtime hook object_without_properties which makes the nested value immutable.

@jasonlyu123
Copy link
Member

object_without_properties returns a new object. But if you have a nested object the property would be referencing the same object.

@Conduitry
Copy link
Member

As of 3.51.0, code like this will produce a compile-time warning - https://svelte.dev/repl/761103ad2e254ee0a95454fc82c314c7?version=3.51.0

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