diff --git a/packages/runtime-core/__tests__/hydration.spec.ts b/packages/runtime-core/__tests__/hydration.spec.ts
index 042f1a735c6..679301c1d38 100644
--- a/packages/runtime-core/__tests__/hydration.spec.ts
+++ b/packages/runtime-core/__tests__/hydration.spec.ts
@@ -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(
+ `foo
`,
+ () =>
+ h(
+ Transition,
+ { appear: true },
+ {
+ default: () =>
+ createElementVNode('div', null, 'foo', PatchFlags.CACHED),
+ },
+ ),
+ )
+ expect(container.firstChild).toMatchInlineSnapshot(`
+
+ foo
+
+ `)
+ expect(vnode.el).toBe(container.firstChild)
+ } finally {
+ __DEV__ = true
+ }
+ })
+
+ // #16427
+ test.each([
+ {
+ name: 'appear',
+ template: `foo
`,
+ html: `foo
`,
+ },
+ {
+ name: ':appear="false"',
+ template: `foo
`,
+ html: `foo
`,
+ },
+ // a native is not the SSR wrapper of an appear transition
+ {
+ name: 'native template',
+ template: `foo
`,
+ html: `foo
`,
+ },
+ {
+ name: 'empty native template',
+ template: ``,
+ html: ``,
+ },
+ ])('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 = ``
diff --git a/packages/runtime-core/src/hydration.ts b/packages/runtime-core/src/hydration.ts
index 6a723569ef5..e1bdada8851 100644
--- a/packages/runtime-core/src/hydration.ts
+++ b/packages/runtime-core/src/hydration.ts
@@ -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 wrapper of a cached
+ // child still needs to be unwrapped (a native is kept)
if (
__DEV__ ||
forcePatch ||
hasDynamicProps ||
- patchFlag !== PatchFlags.CACHED
+ patchFlag !== PatchFlags.CACHED ||
+ (transition && type !== 'template' && isTemplateNode(el))
) {
if (dirs) {
invokeDirectiveHook(vnode, null, parentComponent, 'created')