Skip to content

Commit 08bba09

Browse files
committed
test(ssr): more hydration tests
1 parent fb4856b commit 08bba09

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

packages/compiler-core/__tests__/hydration.spec.ts

+24-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import { createSSRApp, h, ref, nextTick, VNode, Portal } from '@vue/runtime-dom'
1+
import {
2+
createSSRApp,
3+
h,
4+
ref,
5+
nextTick,
6+
VNode,
7+
Portal,
8+
createStaticVNode
9+
} from '@vue/runtime-dom'
210

311
function mountWithHydration(html: string, render: () => any) {
412
const container = document.createElement('div')
@@ -28,6 +36,21 @@ describe('SSR hydration', () => {
2836
expect(container.textContent).toBe('bar')
2937
})
3038

39+
test('comment', () => {
40+
const { vnode, container } = mountWithHydration('<!---->', () => null)
41+
expect(vnode.el).toBe(container.firstChild)
42+
expect(vnode.el.nodeType).toBe(8) // comment
43+
})
44+
45+
test('static', () => {
46+
const html = '<div><span>hello</span></div>'
47+
const { vnode, container } = mountWithHydration(html, () =>
48+
createStaticVNode(html)
49+
)
50+
expect(vnode.el).toBe(container.firstChild)
51+
expect(vnode.el.outerHTML).toBe(html)
52+
})
53+
3154
test('element with text children', async () => {
3255
const msg = ref('foo')
3356
const { vnode, container } = mountWithHydration(
@@ -148,10 +171,6 @@ describe('SSR hydration', () => {
148171
)
149172
})
150173

151-
test('comment', () => {})
152-
153-
test('static', () => {})
154-
155174
// compile SSR + client render fn from the same template & hydrate
156175
test('full compiler integration', () => {})
157176

packages/runtime-core/src/hydration.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,16 @@ export function createHydrationFunctions({
131131
parentComponent: ComponentInternalInstance | null,
132132
optimized: boolean
133133
) => {
134+
optimized = optimized || vnode.dynamicChildren !== null
134135
const { props, patchFlag, shapeFlag } = vnode
135136
// skip props & children if this is hoisted static nodes
136137
if (patchFlag !== PatchFlags.HOISTED) {
137138
// props
138139
if (props !== null) {
139140
if (
140-
patchFlag & PatchFlags.FULL_PROPS ||
141-
patchFlag & PatchFlags.HYDRATE_EVENTS
141+
!optimized ||
142+
(patchFlag & PatchFlags.FULL_PROPS ||
143+
patchFlag & PatchFlags.HYDRATE_EVENTS)
142144
) {
143145
for (const key in props) {
144146
if (!isReservedProp(key) && isOn(key)) {
@@ -172,7 +174,7 @@ export function createHydrationFunctions({
172174
vnode,
173175
el,
174176
parentComponent,
175-
optimized || vnode.dynamicChildren !== null
177+
optimized
176178
)
177179
while (next) {
178180
hasMismatch = true

0 commit comments

Comments
 (0)