From 62e5b44ff69d3bb1f509301d4d61416293259a0a Mon Sep 17 00:00:00 2001 From: eddyerburgh Date: Sat, 28 Jul 2018 12:14:18 +0100 Subject: [PATCH 1/2] fix: render multiple children in default slot --- packages/create-instance/create-slot-vnodes.js | 7 +++++-- packages/create-instance/validate-slots.js | 4 ++-- packages/test-utils/src/mount.js | 3 --- test/specs/mounting-options/slots.spec.js | 9 +++++++++ 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/packages/create-instance/create-slot-vnodes.js b/packages/create-instance/create-slot-vnodes.js index b73bf95b6..56b29e889 100644 --- a/packages/create-instance/create-slot-vnodes.js +++ b/packages/create-instance/create-slot-vnodes.js @@ -22,10 +22,13 @@ function createVNodesForSlot ( vm: Component, slotValue: SlotValue, name: string, -): VNode | string { +): VNode | Array { let vnode if (typeof slotValue === 'string') { const vnodes = createVNodes(vm, slotValue) + if (vnodes.length > 1) { + return vnodes + } vnode = vnodes[0] } else { vnode = vm.$createElement(slotValue) @@ -41,7 +44,7 @@ function createVNodesForSlot ( export function createSlotVNodes ( vm: Component, slots: SlotsObject -): Array { +): Array> { return Object.keys(slots).reduce((acc, key) => { const content = slots[key] if (Array.isArray(content)) { diff --git a/packages/create-instance/validate-slots.js b/packages/create-instance/validate-slots.js index 97d70a99f..34b5432d2 100644 --- a/packages/create-instance/validate-slots.js +++ b/packages/create-instance/validate-slots.js @@ -15,8 +15,8 @@ function requiresTemplateCompiler (slot: any): void { if (typeof slot === 'string' && !compileToFunctions) { throwError( `vueTemplateCompiler is undefined, you must pass ` + - `precompiled components if vue-template-compiler is ` + - `undefined` + `precompiled components if vue-template-compiler is ` + + `undefined` ) } } diff --git a/packages/test-utils/src/mount.js b/packages/test-utils/src/mount.js index 52638d248..4608a9e44 100644 --- a/packages/test-utils/src/mount.js +++ b/packages/test-utils/src/mount.js @@ -42,9 +42,6 @@ export default function mount ( const vm = parentVm.$mount(elm).$refs.vm - // Workaround for Vue < 2.5 - vm._staticTrees = [] - const componentsWithError = findAllVueComponentsFromVm(vm).filter( c => c._error ) diff --git a/test/specs/mounting-options/slots.spec.js b/test/specs/mounting-options/slots.spec.js index 8b085c285..896660180 100644 --- a/test/specs/mounting-options/slots.spec.js +++ b/test/specs/mounting-options/slots.spec.js @@ -347,6 +347,15 @@ describeWithMountingMethods('options.slots', mountingMethod => { } ) + it('supports multiple root nodes in default slot option', () => { + const wrapper = mountingMethod(ComponentWithSlots, { + slots: { + default: ['