Skip to content

Commit 85dd3ec

Browse files
authored
fix: support multiple default slot nodes (#861)
1 parent e2e48dc commit 85dd3ec

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@ function createVNodesForSlot (
2222
vm: Component,
2323
slotValue: SlotValue,
2424
name: string,
25-
): VNode | string {
25+
): VNode | Array<VNode> {
2626
let vnode
2727
if (typeof slotValue === 'string') {
2828
const vnodes = createVNodes(vm, slotValue)
29+
if (vnodes.length > 1) {
30+
return vnodes
31+
}
2932
vnode = vnodes[0]
3033
} else {
3134
vnode = vm.$createElement(slotValue)
@@ -41,7 +44,7 @@ function createVNodesForSlot (
4144
export function createSlotVNodes (
4245
vm: Component,
4346
slots: SlotsObject
44-
): Array<VNode | string> {
47+
): Array<VNode | Array<VNode>> {
4548
return Object.keys(slots).reduce((acc, key) => {
4649
const content = slots[key]
4750
if (Array.isArray(content)) {

Diff for: packages/create-instance/validate-slots.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ function requiresTemplateCompiler (slot: any): void {
1515
if (typeof slot === 'string' && !compileToFunctions) {
1616
throwError(
1717
`vueTemplateCompiler is undefined, you must pass ` +
18-
`precompiled components if vue-template-compiler is ` +
19-
`undefined`
18+
`precompiled components if vue-template-compiler is ` +
19+
`undefined`
2020
)
2121
}
2222
}

Diff for: packages/test-utils/src/mount.js

-3
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ export default function mount (
4242

4343
const vm = parentVm.$mount(elm).$refs.vm
4444

45-
// Workaround for Vue < 2.5
46-
vm._staticTrees = []
47-
4845
const componentsWithError = findAllVueComponentsFromVm(vm).filter(
4946
c => c._error
5047
)

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

+13
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,19 @@ describeWithMountingMethods('options.slots', mountingMethod => {
347347
}
348348
)
349349

350+
it('supports multiple root nodes in default slot option', () => {
351+
const wrapper = mountingMethod(ComponentWithSlots, {
352+
slots: {
353+
default: ['<time /><time />']
354+
}
355+
})
356+
if (mountingMethod.name === 'renderToString') {
357+
expect(wrapper).to.contain('<time></time><time></time>')
358+
} else {
359+
expect(wrapper.findAll('time').length).to.equal(2)
360+
}
361+
})
362+
350363
itDoNotRunIf(
351364
process.env.TEST_ENV === 'node',
352365
'mounts component with named slot if passed string in slot object',

0 commit comments

Comments
 (0)