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

Multiple registers in each block with bind group and no index #5174

Closed
ignatiusmb opened this issue Jul 21, 2020 · 2 comments · Fixed by #5199
Closed

Multiple registers in each block with bind group and no index #5174

ignatiusmb opened this issue Jul 21, 2020 · 2 comments · Fixed by #5199

Comments

@ignatiusmb
Copy link
Member

Describe the bug
Each loop register multiple values in bind:group, adding key expression doesn't help, but adding index strangely solves the problem.

To Reproduce
Buggy: https://svelte.dev/repl/6ee5960e75ac442bb0f8577f98941501?version=3.24.0
Fixed: https://svelte.dev/repl/5738295d14a6406a9f4a1a0b73f403d0?version=3.24.0

Fixed version works without the keys (key)

Expected behavior
Expected that key expression was the one to give each element unique id to bind the group

Information about your Svelte project:

  • Your browser and the version: Firefox Developer 79.0b9
  • Your operating system: Windows 10
  • Svelte version: 3.24.0
  • Uses Rollup

Severity
How severe an issue is this bug to you? Is this annoying, blocking some users, blocking an upgrade or blocking your usage of Svelte entirely?

Annoying, time wasting

@dimfeld
Copy link
Contributor

dimfeld commented Jul 22, 2020

Actually it looks like adding the index variable to the #each expression (i.e. day, d instead of day) is what makes the difference, even if the index isn't used at all.

With the day, d version, we see that the compiled code uses ctx[8] for the index value:

function get_each_context(ctx, list, i) {
	const child_ctx = ctx.slice();
	child_ctx[6] = list[i];
	child_ctx[8] = i;
	return child_ctx;
}

And then in the inner each loop, it uses ctx[8] to index into the binding groups:

/*$$binding_groups*/ ctx[5][0][/*d*/ ctx[8]].push(input);

Without the explicit index, Svelte is still generating an index internally and linking the bind group to it as before:

/*$$binding_groups*/ ctx[5][0][/*day_index*/ ctx[8]].push(input);

But ctx[8] is not actually initialized anymore, so I think all the inputs ends up sharing the same binding group, or something like that.

function get_each_context(ctx, list, i) {
	const child_ctx = ctx.slice();
	child_ctx[6] = list[i];
	return child_ctx;
}

Looks to me like this line needs to add a condition that checks if there is an implicit index.

if (this.node.has_binding || this.node.has_index_binding || this.node.index) this.context_props.push(b`child_ctx[${renderer.context_lookup.get(this.index_name.name).index}] = i;`);

I haven't yet found the flag that indicates if it that implicit index exists or not. If nobody else gets to it first, I'll try to get a fix in later this week.

@Conduitry
Copy link
Member

This is fixed in 3.24.1 - https://svelte.dev/repl/6ee5960e75ac442bb0f8577f98941501?version=3.24.1

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

Successfully merging a pull request may close this issue.

4 participants