From: daiwei Date: Wed, 30 Jul 2025 09:22:09 +0000 (+0800) Subject: fix: use empty comment as if fragment anchor X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9e167236632f23dc69168d6686ace8b297c85046;p=thirdparty%2Fvuejs%2Fcore.git fix: use empty comment as if fragment anchor --- diff --git a/packages/runtime-vapor/src/fragment.ts b/packages/runtime-vapor/src/fragment.ts index 9971183ba1..59de26d08b 100644 --- a/packages/runtime-vapor/src/fragment.ts +++ b/packages/runtime-vapor/src/fragment.ts @@ -13,7 +13,6 @@ import type { TransitionHooks } from '@vue/runtime-dom' import { advanceHydrationNode, currentHydrationNode, - isComment, isHydrating, locateHydrationNode, locateVaporFragmentAnchor, @@ -75,7 +74,7 @@ export class DynamicFragment extends VaporFragment { update(render?: BlockFn, key: any = render): void { if (key === this.current) { - if (isHydrating) this.hydrate(this.anchorLabel!) + if (isHydrating) this.hydrate(this.anchorLabel!, true) return } this.current = key @@ -145,11 +144,11 @@ export class DynamicFragment extends VaporFragment { } } - hydrate(label: string): void { + hydrate(label: string, isEmpty: boolean = false): void { // for `v-if="false"` the node will be an empty comment, use it as the anchor. // otherwise, find next sibling vapor fragment anchor - if (label === 'if' && isComment(currentHydrationNode!, '')) { - this.anchor = currentHydrationNode + if (label === 'if' && isEmpty) { + this.anchor = locateVaporFragmentAnchor(currentHydrationNode!, '')! } else { let anchor = locateVaporFragmentAnchor(currentHydrationNode!, label)! if (!anchor && (label === 'slot' || label === 'if')) {