Skip to content

Commit

Permalink
fix: render all slots inside a <template> vnode (#979)
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyerburgh authored Sep 27, 2018
1 parent 8771b8f commit c04d3bf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
25 changes: 9 additions & 16 deletions packages/create-instance/create-slot-vnodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,32 @@ import { compileToFunctions } from 'vue-template-compiler'

function createVNodes (
vm: Component,
slotValue: string
slotValue: string,
name
): Array<VNode> {
const el = compileToFunctions(`<div>${slotValue}</div>`)
const el = compileToFunctions(
`<div><template slot=${name}>${slotValue}</template></div>`
)
const _staticRenderFns = vm._renderProxy.$options.staticRenderFns
const _staticTrees = vm._renderProxy._staticTrees
vm._renderProxy._staticTrees = []
vm._renderProxy.$options.staticRenderFns = el.staticRenderFns
const vnode = el.render.call(vm._renderProxy, vm.$createElement)
vm._renderProxy.$options.staticRenderFns = _staticRenderFns
vm._renderProxy._staticTrees = _staticTrees
return vnode.children
return vnode.children[0]
}

function createVNodesForSlot (
vm: Component,
slotValue: SlotValue,
name: string,
): VNode | Array<VNode> {
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)
}
if (vnode.data) {
vnode.data.slot = name
} else {
vnode.data = { slot: name }
return createVNodes(vm, slotValue, name)
}
const vnode = vm.$createElement(slotValue)
;(vnode.data || (vnode.data = {})).slot = name
return vnode
}

Expand Down
8 changes: 4 additions & 4 deletions test/specs/mounting-options/slots.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,14 @@ describeWithMountingMethods('options.slots', mountingMethod => {
it('mounts component with default and named text slot', () => {
const wrapper = mountingMethod(ComponentWithSlots, {
slots: {
default: 'hello,',
footer: '<template>world</template>'
footer: 'world',
default: 'hello,'
}
})
if (mountingMethod.name === 'renderToString') {
expect(wrapper).contains('hello,world')
expect(wrapper).contains('hello,</main> <footer>world')
} else {
expect(wrapper.text()).to.contain('hello,world')
expect(wrapper.text()).to.contain('hello, world')
}
})

Expand Down

0 comments on commit c04d3bf

Please sign in to comment.