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

append to the dom, not a document fragment, when updating each block in slot #932

Merged
merged 3 commits into from
Nov 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/generators/dom/visitors/EachBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function visitEachBlock(
const iterations = block.getUniqueName(`${each}_blocks`);
const params = block.params.join(', ');

const needsAnchor = node.next ? !isDomNode(node.next, generator) : !state.parentNode;
const needsAnchor = node.next ? !isDomNode(node.next, generator) : !state.parentNode || !isDomNode(node.parent, generator);
const anchor = needsAnchor
? block.getUniqueName(`${each}_anchor`)
: (node.next && node.next.var) || 'null';
Expand Down Expand Up @@ -219,7 +219,7 @@ function keyed(
`);

const dynamic = node._block.hasUpdateMethod;
const parentNode = state.parentNode || `${anchor}.parentNode`;
const parentNode = isDomNode(node.parent, generator) ? node.parent.var : `${anchor}.parentNode`;

let destroy;
if (node._block.hasOutroMethod) {
Expand Down Expand Up @@ -414,7 +414,7 @@ function unkeyed(
.map(dependency => `changed.${dependency}`)
.join(' || ');

const parentNode = state.parentNode || `${anchor}.parentNode`;
const parentNode = isDomNode(node.parent, generator) ? node.parent.var : `${anchor}.parentNode`;

if (condition !== '') {
const forLoopBody = node._block.hasUpdateMethod
Expand Down
3 changes: 3 additions & 0 deletions test/runtime/samples/component-slot-each-block/Nested.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div>
<slot/>
</div>
24 changes: 24 additions & 0 deletions test/runtime/samples/component-slot-each-block/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export default {
data: {
things: [1, 2, 3]
},

html: `
<div>
<span>1</span>
<span>2</span>
<span>3</span>
</div>`,

test(assert, component, target) {
component.set({ things: [1, 2, 3, 4] });
assert.htmlEqual(target.innerHTML, `
<div>
<span>1</span>
<span>2</span>
<span>3</span>
<span>4</span>
</div>
`);
}
};
13 changes: 13 additions & 0 deletions test/runtime/samples/component-slot-each-block/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Nested>
{{#each things as thing}}
<span>{{thing}}</span>
{{/each}}
</Nested>

<script>
import Nested from './Nested.html';

export default {
components: { Nested }
};
</script>