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

Fix for each-blocks preventing outros from completing #1693

Merged
merged 1 commit into from
Aug 28, 2018
Merged

Conversation

jacwright
Copy link
Contributor

Unkeyed each blocks end up with trailing null values that prevent the whole from being outroed. This fixes it so the null values are removed before outroing the remaining blocks.

Fixes #1617

Unkeyed each blocks end up with trailing `null` values that prevent the whole from being outroed. This fixes it so the null values are removed before outroing the remaining blocks.

Fixes #1617
@Rich-Harris
Copy link
Member

Ah, good sleuthing. It feels like we should be resetting the length at the end of the update in the parent to the each-block:

		p: function update(changed, ctx) {
			if (changed.cats) {
				each_value = ctx.cats;

				for (var i = 0; i < each_value.length; i += 1) {
					const child_ctx = get_each_context(ctx, each_value, i);

					if (each_blocks[i]) {
						each_blocks[i].p(changed, child_ctx);
					} else {
						each_blocks[i] = create_each_block(component, child_ctx);
						each_blocks[i].c();
					}
					each_blocks[i].i(each_anchor.parentNode, each_anchor);
				}

				groupOutros();
				for (; i < each_blocks.length; i += 1) outroBlock(i, 1);
+				each_blocks.length - each_value.length;
			}
		},

I'd look into that but I'm about to call it a night — can revisit in the morning if you don't get there first. The advantage of doing it that way is we're not allocating an extra array (and leaving the old one out for the garbage collector).

@jacwright
Copy link
Contributor Author

I tried that at first, but the aborted-outro-in-each test failed. We can't count the node out until it is finished with its outro.

The most correct way to do it would probably be to splice the node out of the array (instead of setting it to null) when the outro is finished, but I thought the approach I went with would be more performant. I did not do any testing to verify performance behavior between the two.

@Rich-Harris
Copy link
Member

Ah, gotcha. Yeah, that's a tough one — splicing versus copying. Probably depends on the specifics and only amounts to a few microseconds. In it goes 😀

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 this pull request may close these issues.

Nested transitions prevent items from being removed
2 participants