소스 검색

fix: use empty comment as if fragment anchor

daiwei 11 달 전
부모
커밋
9e16723663
1개의 변경된 파일4개의 추가작업 그리고 5개의 파일을 삭제
  1. 4 5
      packages/runtime-vapor/src/fragment.ts

+ 4 - 5
packages/runtime-vapor/src/fragment.ts

@@ -13,7 +13,6 @@ import type { TransitionHooks } from '@vue/runtime-dom'
 import {
 import {
   advanceHydrationNode,
   advanceHydrationNode,
   currentHydrationNode,
   currentHydrationNode,
-  isComment,
   isHydrating,
   isHydrating,
   locateHydrationNode,
   locateHydrationNode,
   locateVaporFragmentAnchor,
   locateVaporFragmentAnchor,
@@ -75,7 +74,7 @@ export class DynamicFragment extends VaporFragment {
 
 
   update(render?: BlockFn, key: any = render): void {
   update(render?: BlockFn, key: any = render): void {
     if (key === this.current) {
     if (key === this.current) {
-      if (isHydrating) this.hydrate(this.anchorLabel!)
+      if (isHydrating) this.hydrate(this.anchorLabel!, true)
       return
       return
     }
     }
     this.current = key
     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.
     // for `v-if="false"` the node will be an empty comment, use it as the anchor.
     // otherwise, find next sibling vapor fragment 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 {
     } else {
       let anchor = locateVaporFragmentAnchor(currentHydrationNode!, label)!
       let anchor = locateVaporFragmentAnchor(currentHydrationNode!, label)!
       if (!anchor && (label === 'slot' || label === 'if')) {
       if (!anchor && (label === 'slot' || label === 'if')) {