Skip to content

fix(hydration): handle transition appear hydration edge case #13339

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

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

test('transition appear work with pre-existing class', () => {
const { vnode, container } = mountWithHydration(
`<template><div class="foo">foo</div></template>`,
() =>
h(
Transition,
{ appear: true },
{
default: () => h('div', { class: 'foo' }, 'foo'),
},
),
)
expect(container.firstChild).toMatchInlineSnapshot(`
<div
class="foo v-enter-from v-enter-active"
>
foo
</div>
`)
expect(vnode.el).toBe(container.firstChild)
expect(`mismatch`).not.toHaveBeenWarned()
})

test('transition appear with v-if', () => {
const show = false
const { vnode, container } = mountWithHydration(
Expand Down
7 changes: 4 additions & 3 deletions packages/runtime-core/src/hydration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,10 @@ export function createHydrationFunctions(
parentComponent.vnode.props.appear

const content = (el as HTMLTemplateElement).content
.firstChild as Element
.firstChild as Element & { $cls: string | null }

if (needCallTransitionHooks) {
content.$cls = content.getAttribute('class')
transition!.beforeEnter(content)
}

Expand Down Expand Up @@ -786,7 +787,7 @@ export function createHydrationFunctions(
* Dev only
*/
function propHasMismatch(
el: Element,
el: Element & { $cls?: string | null },
key: string,
clientValue: any,
vnode: VNode,
Expand All @@ -799,7 +800,7 @@ function propHasMismatch(
if (key === 'class') {
// classes might be in different order, but that doesn't affect cascade
// so we just need to check if the class lists contain the same classes.
actual = el.getAttribute('class')
actual = el.$cls || el.getAttribute('class')
expected = normalizeClass(clientValue)
if (!isSetEqual(toClassSet(actual || ''), toClassSet(expected))) {
mismatchType = MismatchTypes.CLASS
Expand Down