Skip to content
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

fix(Transition): Make transition behavior in KeepAlive in dev-mode consistent with production-mode. #5557

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
12 changes: 11 additions & 1 deletion packages/runtime-core/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1996,7 +1996,17 @@ function baseCreateRenderer(
moveType,
parentSuspense = null
) => {
const { el, type, transition, children, shapeFlag } = vnode
const { el, type, transition, children, shapeFlag, patchFlag } = vnode

if (
__DEV__ &&
patchFlag > 0 &&
patchFlag & PatchFlags.DEV_ROOT_FRAGMENT
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will not work if keep comments in the production build.

) {
const root = filterSingleRoot(children as VNodeArrayChildren)
root && (root.transition = transition)
}

if (shapeFlag & ShapeFlags.COMPONENT) {
move(vnode.component!.subTree, container, anchor, moveType)
return
Expand Down
71 changes: 71 additions & 0 deletions packages/vue/__tests__/Transition.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2091,4 +2091,75 @@ describe('e2e: Transition', () => {
},
E2E_TIMEOUT
)

// #5500
test(`Get the correct name of the Transition component in dev mode`, async () => {
await page().evaluate(duration => {
const { createApp, ref, openBlock, createElementBlock, Fragment, createCommentVNode, createElementVNode } = (window as any).Vue
createApp({
template: `
<div id="container">
<transition :name="view.transitionName" duration="${duration * 2}">
<KeepAlive>
<component :is="view.name"></component>
</KeepAlive>
</transition>
</div>
<button id="changeViewBtn" @click="change">button</button>
`,
components: {
one: {
render() {
return (openBlock(), createElementBlock(Fragment, null, [
createCommentVNode(" Comment! "),
createElementVNode("div", { class: "one" }, "one", -1)
], 2112))
},
},
two: {
template: '<div class=\"two\">two</div>'
}
},
setup: () => {
const view = ref({
name: 'one',
transitionName: 'slide-left'
})
const change = () => {
view.value = {
name: 'two',
transitionName: 'slide-right'
}
}
return { view, change }
},
}).mount('#app')
}, duration)
expect(await html('#container')).toBe('<!-- Comment! --><div class=\"one\">one</div>')

await page().evaluate(() => {
;(document.querySelector('#changeViewBtn') as any)!.click()
})

expect(await classList('.one')).toStrictEqual([
'one',
'slide-right-leave-from',
'slide-right-leave-active'
])

expect(await classList('.two')).toStrictEqual([
'two',
'slide-right-enter-from',
'slide-right-enter-active'
])

await transitionFinish(duration)
expect(await html('#container')).toBe(
`<div class="one slide-right-leave-active slide-right-leave-to">one</div>` +
`<div class="two slide-right-enter-active slide-right-enter-to">two</div>`
)

await transitionFinish(duration)
expect(await html('#container')).toBe(`<div class=\"two\">two</div>`)
}, E2E_TIMEOUT)
})