COMMENT = 8,
}
-let hasMismatch = false
+let hasLoggedMismatchError = false
+const logMismatchError = () => {
+ if (__TEST__ || hasLoggedMismatchError) {
+ return
+ }
+ // this error should show up in production
+ console.error('Hydration completed but contains mismatches.')
+ hasLoggedMismatchError = true
+}
const isSVGContainer = (container: Element) =>
container.namespaceURI!.includes('svg') &&
container._vnode = vnode
return
}
- hasMismatch = false
+
hydrateNode(container.firstChild!, vnode, null, null, null)
flushPostFlushCbs()
container._vnode = vnode
- if (hasMismatch && !__TEST__) {
- // this error should show up in production
- console.error(`Hydration completed but contains mismatches.`)
- }
}
const hydrateNode = (
}
} else {
if ((node as Text).data !== vnode.children) {
- hasMismatch = true
;(__DEV__ || __FEATURE_PROD_HYDRATION_MISMATCH_DETAILS__) &&
warn(
`Hydration text mismatch in`,
)}` +
`\n - expected on client: ${JSON.stringify(vnode.children)}`,
)
+ logMismatchError()
;(node as Text).data = vnode.children as string
}
nextNode = nextSibling(node)
)
let hasWarned = false
while (next) {
- hasMismatch = true
if (
(__DEV__ || __FEATURE_PROD_HYDRATION_MISMATCH_DETAILS__) &&
!hasWarned
)
hasWarned = true
}
+ logMismatchError()
+
// The SSRed DOM contains more nodes than it should. Remove them.
const cur = next
next = next.nextSibling
}
} else if (shapeFlag & ShapeFlags.TEXT_CHILDREN) {
if (el.textContent !== vnode.children) {
- hasMismatch = true
;(__DEV__ || __FEATURE_PROD_HYDRATION_MISMATCH_DETAILS__) &&
warn(
`Hydration text content mismatch on`,
`\n - rendered on server: ${el.textContent}` +
`\n - expected on client: ${vnode.children as string}`,
)
+ logMismatchError()
+
el.textContent = vnode.children as string
}
}
(__DEV__ || __FEATURE_PROD_HYDRATION_MISMATCH_DETAILS__) &&
propHasMismatch(el, key, props[key], vnode, parentComponent)
) {
- hasMismatch = true
+ logMismatchError()
}
if (
(forcePatch &&
// because server rendered HTML won't contain a text node
insert((vnode.el = createText('')), container)
} else {
- hasMismatch = true
if (
(__DEV__ || __FEATURE_PROD_HYDRATION_MISMATCH_DETAILS__) &&
!hasWarned
)
hasWarned = true
}
+ logMismatchError()
+
// the SSRed DOM didn't contain enough nodes. Mount the missing ones.
patch(
null,
} else {
// fragment didn't hydrate successfully, since we didn't get a end anchor
// back. This should have led to node/children mismatch warnings.
- hasMismatch = true
+ logMismatchError()
+
// since the anchor is missing, we need to create one and insert it
insert((vnode.anchor = createComment(`]`)), container, next)
return next
slotScopeIds: string[] | null,
isFragment: boolean,
): Node | null => {
- hasMismatch = true
;(__DEV__ || __FEATURE_PROD_HYDRATION_MISMATCH_DETAILS__) &&
warn(
`Hydration node mismatch:\n- rendered on server:`,
`\n- expected on client:`,
vnode.type,
)
+ logMismatchError()
+
vnode.el = null
if (isFragment) {