expect(`Hydration node mismatch`).not.toHaveBeenWarned()
})
+ test('comment mismatch (v-if)', () => {
+ const { container } = mountWithHydration(`<!--v-if-->`, () =>
+ h('div', { 'data-allow-mismatch': '' }, [h('span', 'value')]),
+ )
+ expect(container.innerHTML).toBe(
+ '<div data-allow-mismatch=""><span>value</span></div>',
+ )
+ expect(`Hydration node mismatch`).not.toHaveBeenWarned()
+ })
+
test('comment mismatch (text)', () => {
const { container } = mountWithHydration(
`<div data-allow-mismatch="children">foobar</div>`,
slotScopeIds: string[] | null,
isFragment: boolean,
): Node | null => {
- if (!isMismatchAllowed(node.parentElement!, MismatchTypes.CHILDREN)) {
+ if (
+ !isMismatchAllowed(node.parentElement!, MismatchTypes.CHILDREN) &&
+ !isCommentNodeMismatch(node, vnode)
+ ) {
;(__DEV__ || __FEATURE_PROD_HYDRATION_MISMATCH_DETAILS__) &&
warn(
`Hydration node mismatch:\n- rendered on server:`,
return allowedAttr.split(',').includes(MismatchTypeString[allowedType])
}
}
+
+// data-allow-mismatch + v-if
+function isCommentNodeMismatch(node: Node, vnode: VNode): boolean {
+ if (node.nodeType !== DOMNodeTypes.COMMENT || !vnode.props) {
+ return false
+ }
+
+ return allowMismatchAttr in vnode.props
+}