Skip to content

Commit 4a0fa08

Browse files
committed
wip: save
1 parent 947e076 commit 4a0fa08

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

packages/runtime-vapor/src/dom/hydration.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function finalizeHydrationBoundary(boundary: HydrationBoundary): void {
6060
return
6161
}
6262

63-
warnHydrationChildrenMismatch((close as Node).parentElement!)
63+
warnHydrationChildrenMismatch((close as Node).parentElement)
6464

6565
while (node && node !== close) {
6666
const next = locateNextNode(node)
@@ -71,8 +71,8 @@ function finalizeHydrationBoundary(boundary: HydrationBoundary): void {
7171
setCurrentHydrationNode(close)
7272
}
7373

74-
function warnHydrationChildrenMismatch(container: Element): void {
75-
if (!isMismatchAllowed(container, MismatchTypes.CHILDREN)) {
74+
function warnHydrationChildrenMismatch(container: Element | null): void {
75+
if (container && !isMismatchAllowed(container, MismatchTypes.CHILDREN)) {
7676
;(__DEV__ || __FEATURE_PROD_HYDRATION_MISMATCH_DETAILS__) &&
7777
warn(
7878
`Hydration children mismatch on`,
@@ -420,33 +420,44 @@ export const logMismatchError = (): void => {
420420
}
421421

422422
export function removeFragmentNodes(node: Node, endAnchor?: Node): void {
423+
const parent = parentNode(node)
424+
if (!parent) {
425+
return
426+
}
423427
const end = endAnchor || locateEndAnchor(node as CommentAnchor)
424428
while (true) {
425429
const next = _next(node)
426430
if (next && next !== end) {
427-
remove(next, parentNode(node)!)
431+
remove(next, parent)
428432
} else {
429433
break
430434
}
431435
}
432436
}
433437

434438
function removeHydrationNode(node: Node, close: Node | null = null): void {
439+
const parent = parentNode(node)
440+
if (!parent) {
441+
return
442+
}
443+
435444
if (isComment(node, '[')) {
436445
const end = locateEndAnchor(node)
437446
removeFragmentNodes(node, end || undefined)
438-
if (end && end !== close) {
439-
remove(end, parentNode(end)!)
447+
const endParent = end && parentNode(end)
448+
if (end && end !== close && endParent) {
449+
remove(end, endParent)
440450
}
441451
} else if (isComment(node, 'teleport start')) {
442452
const end = locateEndAnchor(node, 'teleport start', 'teleport end')
443453
removeFragmentNodes(node, end || undefined)
444-
if (end && end !== close) {
445-
remove(end, parentNode(end)!)
454+
const endParent = end && parentNode(end)
455+
if (end && end !== close && endParent) {
456+
remove(end, endParent)
446457
}
447458
}
448459

449-
remove(node, parentNode(node)!)
460+
remove(node, parent)
450461
}
451462

452463
export function cleanupHydrationTail(node: Node): void {

0 commit comments

Comments
 (0)