Skip to content

Commit 47ab23c

Browse files
authored
Merge pull request #2097 from sveltejs/gh-2031-with-fix
assign elements to correct block when slots are involved
2 parents d0b93ee + 5c7fdf4 commit 47ab23c

File tree

5 files changed

+35
-3
lines changed

5 files changed

+35
-3
lines changed

src/compile/render-dom/wrappers/Element/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@ export default class ElementWrapper extends Wrapper {
203203

204204
if (this.slot_block) {
205205
block.parent.addDependencies(block.dependencies);
206+
207+
// appalling hack
208+
block.wrappers.splice(block.wrappers.indexOf(this), 1);
209+
this.slot_block.wrappers.push(this);
206210
}
207211
}
208212

@@ -216,13 +220,13 @@ export default class ElementWrapper extends Wrapper {
216220

217221
if (this.node.name === 'noscript') return;
218222

219-
const node = this.var;
220-
const nodes = parentNodes && block.getUniqueName(`${this.var}_nodes`) // if we're in unclaimable territory, i.e. <head>, parentNodes is null
221-
222223
if (this.slot_block) {
223224
block = this.slot_block;
224225
}
225226

227+
const node = this.var;
228+
const nodes = parentNodes && block.getUniqueName(`${this.var}_nodes`) // if we're in unclaimable territory, i.e. <head>, parentNodes is null
229+
226230
block.addVariable(node);
227231
const renderStatement = this.getRenderStatement();
228232
block.builders.create.addLine(
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script>
2+
import Two from './Two.svelte';
3+
</script>
4+
5+
<Two>
6+
<div slot="b">
7+
<div>
8+
<slot name="a"></slot>
9+
</div>
10+
</div>
11+
</Two>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<slot name="b"></slot>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export default {
2+
html: `
3+
<div slot="b">
4+
<div>
5+
<div slot="a">a</div>
6+
</div>
7+
</div>
8+
`
9+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script>
2+
import One from './One.svelte';
3+
</script>
4+
5+
<One>
6+
<div slot="a">a</div>
7+
</One>

0 commit comments

Comments
 (0)