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

Name collision in each disables binding #4757

Closed
BulatDashiev opened this issue May 1, 2020 · 5 comments · Fixed by #4861
Closed

Name collision in each disables binding #4757

BulatDashiev opened this issue May 1, 2020 · 5 comments · Fixed by #4861
Labels

Comments

@BulatDashiev
Copy link

Describe the bug
Name collision between expression name and property name in destructed object disables bind to work on that property

{#each a as { a }}
  <input bind:value={a} />
{/each}

To Reproduce
https://svelte.dev/repl/d4fe2df9f4474da985dd2c6afa6876f3?version=3.21.0

Expected behavior
Property inside an object should change when input changed

Information about your Svelte project:

  • Svelte version 3.21.0

Severity
Annoying. Of course that applieable in very small cases but i think it should work

Workaround
Renaming the property name fix problem

{#each a as { a: b }}
  <input bind:value={b} />
{/each}

Would work

@Conduitry Conduitry added the bug label May 2, 2020
@SulpherStaer
Copy link

This doesn't seem like a bug. That just stops bad habits. As this is now a set that contains itself?

Why exactly is it a bug that your not allowed to use the same variable name to do a different thing with what it contains?

@BulatDashiev
Copy link
Author

BulatDashiev commented May 5, 2020

As this is now a set that contains itself?
No it's not it's just a property inside inject with the same name as variable.

const id = {
id: 1,
name: 'abc'
};

Why exactly is it a bug that your not allowed to use the same variable name to do a different thing with what it contains?

I assume that the result of destruction in new scope like inside block of each loop

@Conduitry
Copy link
Member

<script>
	let a = [
		'Hello'
	];
</script>

{#each a as a}
	{a}
	<input bind:value={a} />
{/each}

also doesn't work it looks like, so I don't think this is specific to destructuring. I sort of feel there was another issue for this at some point (which I don't recall whether it was closed or not) but if it existed I cannot find it now.

@BillyLevin
Copy link
Contributor

@sylcai I think it kinda is a bug since on the initial render, the a being used is correct. You can see it says "Hello" at first. So if you get to that point without erroring, you'd expect it to continue working.

Not sure if this is something that should be fixed or if there should just be a warning/error if you try to do this?

@Conduitry
Copy link
Member

This is fixed in 3.23.1.

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

Successfully merging a pull request may close this issue.

4 participants