Skip to content

Commit 1adadd0

Browse files
author
Richard Browning
committed
Fix vuejs#1868, slots now work inside a div
1 parent 9965f5f commit 1adadd0

File tree

3 files changed

+38
-9
lines changed

3 files changed

+38
-9
lines changed

Diff for: packages/create-instance/create-component-stubs.js

+3-9
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,8 @@ function getScopedSlotRenderFunctions(ctx: any): Array<string> {
7777
// In Vue 2.6+ a new v-slot syntax was introduced
7878
// scopedSlots are now saved in parent._vnode.data.scopedSlots
7979
// We filter out _normalized, $stable and $key keys
80-
if (
81-
ctx &&
82-
ctx.$options &&
83-
ctx.$options.parent &&
84-
ctx.$options.parent._vnode &&
85-
ctx.$options.parent._vnode.data &&
86-
ctx.$options.parent._vnode.data.scopedSlots
87-
) {
88-
const slotKeys: Array<string> = ctx.$options.parent._vnode.data.scopedSlots
80+
if (ctx && ctx.$vnode && ctx.$vnode.data && ctx.$vnode.data.scopedSlots) {
81+
const slotKeys: Array<string> = ctx.$vnode.data.scopedSlots
8982
return keys(slotKeys).filter(
9083
x => x !== '_normalized' && x !== '$stable' && x !== '$key'
9184
)
@@ -94,6 +87,7 @@ function getScopedSlotRenderFunctions(ctx: any): Array<string> {
9487
return []
9588
}
9689

90+
9791
export function createStubFromComponent(
9892
originalComponent: Component,
9993
name: string,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<template>
2+
<div>
3+
<ComponentWithVSlot>
4+
<template v-slot:newSyntax>
5+
<p class="new-example">new slot syntax</p>
6+
</template>
7+
</ComponentWithVSlot>
8+
</div>
9+
</template>
10+
11+
<script>
12+
import ComponentWithVSlot from './component-with-v-slot.vue'
13+
14+
export default {
15+
name: 'ComponentWithVSlotSyntaxNested',
16+
17+
components: { ComponentWithVSlot }
18+
}
19+
</script>

Diff for: test/specs/shallow-mount.spec.js

+16
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import ComponentWithLifecycleHooks from '~resources/components/component-with-li
99
import ComponentWithoutName from '~resources/components/component-without-name.vue'
1010
import ComponentAsAClassWithChild from '~resources/components/component-as-a-class-with-child.vue'
1111
import ComponentWithVSlotSyntax from '~resources/components/component-with-v-slot-syntax.vue'
12+
import ComponentWithVSlotSyntaxNested from '~resources/components/component-with-v-slot-syntax-nested.vue'
13+
import ComponentWithVSlot from '~resources/components/component-with-v-slot.vue'
1214
import ComponentWithVSlot from '~resources/components/component-with-v-slot.vue'
1315
import RecursiveComponent from '~resources/components/recursive-component.vue'
1416
import { vueVersion } from '~resources/utils'
@@ -128,6 +130,20 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
128130
)
129131
})
130132

133+
it('renders SFC with named slots with v-slot syntax nested in a div', () => {
134+
const wrapper = shallowMount(ComponentWithVSlotSyntaxNested)
135+
136+
expect(wrapper.find(ComponentWithVSlot).exists()).toEqual(true)
137+
expect(wrapper.find('.new-example').exists()).toEqual(true)
138+
expect(wrapper.html()).toEqual(
139+
'<div>\n' +
140+
' <componentwithvslot-stub>\n' +
141+
' <p class="new-example">new slot syntax</p>\n' +
142+
' </componentwithvslot-stub>\n' +
143+
'</div>'
144+
)
145+
})
146+
131147
it('renders SFC with named slots with v-slot syntax', () => {
132148
const wrapper = shallowMount(ComponentWithVSlotSyntax)
133149

0 commit comments

Comments
 (0)