Skip to content

fix(runtime-core): KeepAlive/BeseTransition should work with setScopeId + slot #2914

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
serialize,
VNodeProps,
KeepAlive,
TestElement
TestElement,
withScopeId
} from '@vue/runtime-test'

function mount(
Expand Down Expand Up @@ -1090,5 +1091,34 @@ describe('BaseTransition', () => {
test('w/ KeepAlive', async () => {
await runTestWithKeepAlive(testInOutBeforeFinish)
})

// #2892
test('should work with slots + scopeId', async () => {
const withChildId = withScopeId('foo')
const withRootId = withScopeId('root')

const Child = {
render: withChildId(function(this: any) {
return h(BaseTransition, null, {
default: withChildId(() =>
h('div', null, h('div', this.$slots.default()))
)
})
})
}

const App = {
render: withRootId(() =>
h(Child, null, {
default: withRootId(() => h('div'))
})
)
}
const root = nodeOps.createElement('div')
render(h(App), root)
expect(serializeInner(root)).toBe(
`<div foo root><div foo><div root foo-s></div></div></div>`
)
})
})
})
28 changes: 28 additions & 0 deletions packages/runtime-core/__tests__/components/KeepAlive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -825,4 +825,32 @@ describe('KeepAlive', () => {
await nextTick()
expect(serializeInner(root)).toBe(`<div foo>changed</div>`)
})

// #2892
test('should work with slots + scopeId', async () => {
const withChildId = withScopeId('foo')
const withRootId = withScopeId('root')

const Child = {
render: withChildId(function(this: any) {
return h(KeepAlive, null, {
default: withChildId(() =>
h('div', null, h('div', this.$slots.default()))
)
})
})
}

const App = {
render: withRootId(() =>
h(Child, null, {
default: withRootId(() => h('div'))
})
)
}
render(h(App), root)
expect(serializeInner(root)).toBe(
`<div foo root><div foo><div root foo-s></div></div></div>`
)
})
})
4 changes: 2 additions & 2 deletions packages/runtime-core/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -805,13 +805,13 @@ function baseCreateRenderer(
hostSetScopeId(el, scopeId)
}
if (parentComponent) {
const treeOwnerId = parentComponent.type.__scopeId
let subTree = parentComponent.subTree
const treeOwnerId = subTree.scopeId
// vnode's own scopeId and the current patched component's scopeId is
// different - this is a slot content node.
if (treeOwnerId && treeOwnerId !== scopeId) {
hostSetScopeId(el, treeOwnerId + '-s')
}
let subTree = parentComponent.subTree
if (__DEV__ && subTree.type === Fragment) {
subTree =
filterSingleRoot(subTree.children as VNodeArrayChildren) || subTree
Expand Down