Skip to content
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
70 changes: 70 additions & 0 deletions packages/runtime-core/__tests__/hydration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3325,6 +3325,76 @@ describe('SSR hydration', () => {
expect(`mismatch`).not.toHaveBeenWarned()
})

// #16427
test('transition appear with cached static child in prod', () => {
__DEV__ = false
try {
const { vnode, container } = mountWithHydration(
`<template><div>foo</div></template>`,
() =>
h(
Transition,
{ appear: true },
{
default: () =>
createElementVNode('div', null, 'foo', PatchFlags.CACHED),
},
),
)
expect(container.firstChild).toMatchInlineSnapshot(`
<div
class="v-enter-from v-enter-active"
>
foo
</div>
`)
expect(vnode.el).toBe(container.firstChild)
} finally {
__DEV__ = true
}
})

// #16427
test.each([
{
name: 'appear',
template: `<Transition appear><div>foo</div></Transition>`,
html: `<div class="v-enter-from v-enter-active">foo</div>`,
},
{
name: ':appear="false"',
template: `<Transition :appear="false"><div>foo</div></Transition>`,
html: `<div>foo</div>`,
},
// a native <template> is not the SSR wrapper of an appear transition
{
name: 'native template',
template: `<Transition><template><div>foo</div></template></Transition>`,
html: `<template><div>foo</div></template>`,
},
{
name: 'empty native template',
template: `<Transition><template></template></Transition>`,
html: `<template></template>`,
},
])('cached transition child in prod: $name', async ({ template, html }) => {
const App = {
render: compileToFunction(template),
ssrRender: new Function('require', compileSSR(template).code)(
(id: string) => (id === 'vue' ? runtimeDom : serverRenderer),
),
}
const container = document.createElement('div')
container.innerHTML = await renderToString(h(App))
__DEV__ = false
try {
createSSRApp(App).mount(container)
} finally {
__DEV__ = true
}
expect(container.innerHTML).toBe(html)
})

test('transition appear w/ event listener', async () => {
const container = document.createElement('div')
container.innerHTML = `<template><button>0</button></template>`
Expand Down
5 changes: 4 additions & 1 deletion packages/runtime-core/src/hydration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,11 +406,14 @@ export function createHydrationFunctions(
const hasDynamicProps = !!dynamicProps
// skip props & children if this is hoisted static nodes
// #5405 in dev, always hydrate children for HMR
// #16427 the SSR <template> wrapper of a cached <Transition appear>
// child still needs to be unwrapped (a native <template> is kept)
if (
__DEV__ ||
forcePatch ||
hasDynamicProps ||
patchFlag !== PatchFlags.CACHED
patchFlag !== PatchFlags.CACHED ||
(transition && type !== 'template' && isTemplateNode(el))
) {
if (dirs) {
invokeDirectiveHook(vnode, null, parentComponent, 'created')
Expand Down
Loading