From f597d30e7249952e09116eec6155412773e185b0 Mon Sep 17 00:00:00 2001 From: daiwei Date: Thu, 14 Aug 2025 21:31:46 +0800 Subject: [PATCH] chore: tweaks --- packages/runtime-vapor/src/dom/hydration.ts | 23 ++++++++++ packages/runtime-vapor/src/dom/node.ts | 49 ++++----------------- 2 files changed, 31 insertions(+), 41 deletions(-) diff --git a/packages/runtime-vapor/src/dom/hydration.ts b/packages/runtime-vapor/src/dom/hydration.ts index 47b6a69866..09730e3292 100644 --- a/packages/runtime-vapor/src/dom/hydration.ts +++ b/packages/runtime-vapor/src/dom/hydration.ts @@ -223,3 +223,26 @@ function locateHydrationNodeByAnchor( } return null } + +export function skipBlockNodes(node: Node): Node { + while (node) { + if (isComment(node, `[${BLOCK_PREPEND_ANCHOR_LABEL}`)) { + node = locateEndAnchor( + node, + `[${BLOCK_PREPEND_ANCHOR_LABEL}`, + `${BLOCK_PREPEND_ANCHOR_LABEL}]`, + )! + continue + } else if (isComment(node, `[${BLOCK_INSERTION_ANCHOR_LABEL}`)) { + node = locateEndAnchor( + node, + `[${BLOCK_INSERTION_ANCHOR_LABEL}`, + `${BLOCK_INSERTION_ANCHOR_LABEL}]`, + )! + continue + } + + break + } + return node +} diff --git a/packages/runtime-vapor/src/dom/node.ts b/packages/runtime-vapor/src/dom/node.ts index 6975f17d87..19d906e27f 100644 --- a/packages/runtime-vapor/src/dom/node.ts +++ b/packages/runtime-vapor/src/dom/node.ts @@ -1,9 +1,5 @@ -import { isComment, locateEndAnchor } from './hydration' -import { - BLOCK_INSERTION_ANCHOR_LABEL, - BLOCK_PREPEND_ANCHOR_LABEL, - isInsertionAnchor, -} from '@vue/shared' +import { skipBlockNodes } from './hydration' +import { isInsertionAnchor } from '@vue/shared' /*! #__NO_SIDE_EFFECTS__ */ export function createElement(tagName: string): HTMLElement { @@ -25,29 +21,6 @@ export function querySelector(selectors: string): Element | null { return document.querySelector(selectors) } -function skipBlockNodes(node: Node): Node { - while (node) { - if (isComment(node, `[${BLOCK_PREPEND_ANCHOR_LABEL}`)) { - node = locateEndAnchor( - node, - `[${BLOCK_PREPEND_ANCHOR_LABEL}`, - `${BLOCK_PREPEND_ANCHOR_LABEL}]`, - )! - continue - } else if (isComment(node, `[${BLOCK_INSERTION_ANCHOR_LABEL}`)) { - node = locateEndAnchor( - node, - `[${BLOCK_INSERTION_ANCHOR_LABEL}`, - `${BLOCK_INSERTION_ANCHOR_LABEL}]`, - )! - continue - } - - break - } - return node -} - /*! #__NO_SIDE_EFFECTS__ */ const _txt: typeof _child = _child @@ -78,15 +51,11 @@ export function _child(node: ParentNode): Node { */ /*! #__NO_SIDE_EFFECTS__ */ export function __child(node: ParentNode): Node { - let n = node.firstChild! - while (n && (isComment(n, '[') || isInsertionAnchor(n))) { + let n: Node = node.firstChild! + while (n && isInsertionAnchor(n)) { // skip block node - n = skipBlockNodes(n) as ChildNode - if (isComment(n, '[')) { - n = locateEndAnchor(n)!.nextSibling! - } else { - n = n.nextSibling! - } + n = skipBlockNodes(n) + n = n.nextSibling! } return n @@ -119,11 +88,9 @@ export function _next(node: Node): Node { */ /*! #__NO_SIDE_EFFECTS__ */ export function __next(node: Node): Node { - // process fragment (...) as a single node - if (isComment(node, '[')) { - node = locateEndAnchor(node)! + if (isInsertionAnchor(node)) { + node = skipBlockNodes(node) } - node = skipBlockNodes(node) return node.nextSibling! } -- 2.47.3