fix(runtime-core): fix scopeId inheritance for component inside slots
This commit is contained in:
parent
0dd5cde861
commit
978d9522e8
@ -45,13 +45,18 @@ describe('scopeId runtime support', () => {
|
|||||||
return h('div', this.$slots.default())
|
return h('div', this.$slots.default())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
const withChil2Id = withScopeId('child2')
|
||||||
|
const Child2 = {
|
||||||
|
__scopeId: 'child2',
|
||||||
|
render: withChil2Id(() => h('span'))
|
||||||
|
}
|
||||||
const App = {
|
const App = {
|
||||||
__scopeId: 'parent',
|
__scopeId: 'parent',
|
||||||
render: withParentId(() => {
|
render: withParentId(() => {
|
||||||
return h(
|
return h(
|
||||||
Child,
|
Child,
|
||||||
withParentId(() => {
|
withParentId(() => {
|
||||||
return h('div')
|
return [h('div'), h(Child2)]
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@ -62,7 +67,14 @@ describe('scopeId runtime support', () => {
|
|||||||
// - scopeId from parent
|
// - scopeId from parent
|
||||||
// - slotted scopeId (with `-s` postfix) from child (the tree owner)
|
// - slotted scopeId (with `-s` postfix) from child (the tree owner)
|
||||||
expect(serializeInner(root)).toBe(
|
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>`
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -42,6 +42,7 @@ export function renderComponentRoot(
|
|||||||
): VNode {
|
): VNode {
|
||||||
const {
|
const {
|
||||||
type: Component,
|
type: Component,
|
||||||
|
parent,
|
||||||
vnode,
|
vnode,
|
||||||
proxy,
|
proxy,
|
||||||
withProxy,
|
withProxy,
|
||||||
@ -148,9 +149,15 @@ export function renderComponentRoot(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// inherit scopeId
|
// inherit scopeId
|
||||||
if (vnode.scopeId) {
|
const scopeId = vnode.scopeId
|
||||||
root = cloneVNode(root, { [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
|
// inherit directives
|
||||||
if (vnode.dirs) {
|
if (vnode.dirs) {
|
||||||
if (__DEV__ && !isElementRoot(root)) {
|
if (__DEV__ && !isElementRoot(root)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user