Skip to content

Commit

Permalink
fix(setup): ensure setup context slots can be accessed immediately
Browse files Browse the repository at this point in the history
fix #12672
  • Loading branch information
yyx990803 committed Jul 16, 2022
1 parent ea5d0f3 commit 67760f8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/core/instance/render.ts
Expand Up @@ -25,7 +25,13 @@ export function initRender(vm: Component) {
const parentVnode = (vm.$vnode = options._parentVnode!) // the placeholder node in parent tree
const renderContext = parentVnode && (parentVnode.context as Component)
vm.$slots = resolveSlots(options._renderChildren, renderContext)
vm.$scopedSlots = emptyObject
vm.$scopedSlots = parentVnode
? normalizeScopedSlots(
vm.$parent!,
parentVnode.data!.scopedSlots,
vm.$slots
)
: emptyObject
// bind the createElement fn to this instance
// so that we get proper render context inside it.
// args order: tag, data, children, normalizationType, alwaysNormalize
Expand Down Expand Up @@ -98,7 +104,7 @@ export function renderMixin(Vue: typeof Component) {
const vm: Component = this
const { render, _parentVnode } = vm.$options

if (_parentVnode) {
if (_parentVnode && vm._isMounted) {
vm.$scopedSlots = normalizeScopedSlots(
vm.$parent!,
_parentVnode.data!.scopedSlots,
Expand Down
3 changes: 3 additions & 0 deletions test/unit/features/v3/apiSetup.spec.ts
Expand Up @@ -165,6 +165,9 @@ describe('api: setup context', () => {

const Child = {
setup(_props: any, { slots }: any) {
// #12672 behavior consistency with Vue 3: should be able to access
// slots directly in setup()
expect(slots.foo()).toBeTruthy()
return () => h('div', [...slots.foo(), ...slots.bar()])
}
}
Expand Down

0 comments on commit 67760f8

Please sign in to comment.