mirror of https://github.com/vuejs/core.git
Merge b2efba8ff0
into ba391f5fdf
This commit is contained in:
commit
0a25ace261
|
@ -2379,6 +2379,16 @@ describe('SSR hydration', () => {
|
|||
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>`,
|
||||
|
|
|
@ -19,6 +19,7 @@ import {
|
|||
ShapeFlags,
|
||||
def,
|
||||
getEscapedCssVarName,
|
||||
hasOwn,
|
||||
includeBooleanAttr,
|
||||
isBooleanAttr,
|
||||
isKnownHtmlAttr,
|
||||
|
@ -677,7 +678,10 @@ export function createHydrationFunctions(
|
|||
slotScopeIds: string[] | null,
|
||||
isFragment: boolean,
|
||||
): Node | null => {
|
||||
if (!isMismatchAllowed(node.parentElement!, MismatchTypes.CHILDREN)) {
|
||||
if (
|
||||
!isMismatchAllowed(node.parentElement!, MismatchTypes.CHILDREN) &&
|
||||
!isMismatchAllowedForCommentNode(node, vnode)
|
||||
) {
|
||||
;(__DEV__ || __FEATURE_PROD_HYDRATION_MISMATCH_DETAILS__) &&
|
||||
warn(
|
||||
`Hydration node mismatch:\n- rendered on server:`,
|
||||
|
@ -1000,3 +1004,11 @@ function isMismatchAllowed(
|
|||
return list.includes(MismatchTypeString[allowedType])
|
||||
}
|
||||
}
|
||||
|
||||
// data-allow-mismatch + v-if
|
||||
function isMismatchAllowedForCommentNode(
|
||||
node: Node,
|
||||
{ props }: VNode,
|
||||
): boolean {
|
||||
return isComment(node) && props != null && hasOwn(props, allowMismatchAttr)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue