Skip to content

Commit

Permalink
fix(runtime-core): fix scopeId inheritance for component inside slots
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jun 27, 2020
1 parent 0dd5cde commit 978d952
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
16 changes: 14 additions & 2 deletions packages/runtime-core/__tests__/helpers/scopeId.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,18 @@ describe('scopeId runtime support', () => {
return h('div', this.$slots.default())
})
}
const withChil2Id = withScopeId('child2')
const Child2 = {
__scopeId: 'child2',
render: withChil2Id(() => h('span'))
}
const App = {
__scopeId: 'parent',
render: withParentId(() => {
return h(
Child,
withParentId(() => {
return h('div')
return [h('div'), h(Child2)]
})
)
})
Expand All @@ -62,7 +67,14 @@ describe('scopeId runtime support', () => {
// - scopeId from parent
// - slotted scopeId (with `-s` postfix) from child (the tree owner)
expect(serializeInner(root)).toBe(
`<div parent child><div parent child-s></div></div>`
`<div parent child>` +
`<div parent child-s></div>` +
// component inside slot should have:
// - scopeId from template context
// - slotted scopeId from slot owner
// - its own scopeId
`<span parent child-s child2></span>` +
`</div>`
)
})
})
11 changes: 9 additions & 2 deletions packages/runtime-core/src/componentRenderUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export function renderComponentRoot(
): VNode {
const {
type: Component,
parent,
vnode,
proxy,
withProxy,
Expand Down Expand Up @@ -148,9 +149,15 @@ export function renderComponentRoot(
}

// inherit scopeId
if (vnode.scopeId) {
root = cloneVNode(root, { [vnode.scopeId]: '' })
const scopeId = vnode.scopeId
if (scopeId) {
root = cloneVNode(root, { [scopeId]: '' })
}
const treeOwnerId = parent && parent.type.__scopeId
if (treeOwnerId && treeOwnerId !== scopeId) {
root = cloneVNode(root, { [treeOwnerId + '-s']: '' })
}

// inherit directives
if (vnode.dirs) {
if (__DEV__ && !isElementRoot(root)) {
Expand Down

0 comments on commit 978d952

Please sign in to comment.