Skip to content

Commit c04d3bf

Browse files
authored
fix: render all slots inside a <template> vnode (#979)
1 parent 8771b8f commit c04d3bf

File tree

2 files changed

+13
-20
lines changed

2 files changed

+13
-20
lines changed

Diff for: packages/create-instance/create-slot-vnodes.js

+9-16
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,32 @@ import { compileToFunctions } from 'vue-template-compiler'
44

55
function createVNodes (
66
vm: Component,
7-
slotValue: string
7+
slotValue: string,
8+
name
89
): Array<VNode> {
9-
const el = compileToFunctions(`<div>${slotValue}</div>`)
10+
const el = compileToFunctions(
11+
`<div><template slot=${name}>${slotValue}</template></div>`
12+
)
1013
const _staticRenderFns = vm._renderProxy.$options.staticRenderFns
1114
const _staticTrees = vm._renderProxy._staticTrees
1215
vm._renderProxy._staticTrees = []
1316
vm._renderProxy.$options.staticRenderFns = el.staticRenderFns
1417
const vnode = el.render.call(vm._renderProxy, vm.$createElement)
1518
vm._renderProxy.$options.staticRenderFns = _staticRenderFns
1619
vm._renderProxy._staticTrees = _staticTrees
17-
return vnode.children
20+
return vnode.children[0]
1821
}
1922

2023
function createVNodesForSlot (
2124
vm: Component,
2225
slotValue: SlotValue,
2326
name: string,
2427
): VNode | Array<VNode> {
25-
let vnode
2628
if (typeof slotValue === 'string') {
27-
const vnodes = createVNodes(vm, slotValue)
28-
if (vnodes.length > 1) {
29-
return vnodes
30-
}
31-
vnode = vnodes[0]
32-
} else {
33-
vnode = vm.$createElement(slotValue)
34-
}
35-
if (vnode.data) {
36-
vnode.data.slot = name
37-
} else {
38-
vnode.data = { slot: name }
29+
return createVNodes(vm, slotValue, name)
3930
}
31+
const vnode = vm.$createElement(slotValue)
32+
;(vnode.data || (vnode.data = {})).slot = name
4033
return vnode
4134
}
4235

Diff for: test/specs/mounting-options/slots.spec.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,14 @@ describeWithMountingMethods('options.slots', mountingMethod => {
237237
it('mounts component with default and named text slot', () => {
238238
const wrapper = mountingMethod(ComponentWithSlots, {
239239
slots: {
240-
default: 'hello,',
241-
footer: '<template>world</template>'
240+
footer: 'world',
241+
default: 'hello,'
242242
}
243243
})
244244
if (mountingMethod.name === 'renderToString') {
245-
expect(wrapper).contains('hello,world')
245+
expect(wrapper).contains('hello,</main> <footer>world')
246246
} else {
247-
expect(wrapper.text()).to.contain('hello,world')
247+
expect(wrapper.text()).to.contain('hello, world')
248248
}
249249
})
250250

0 commit comments

Comments
 (0)