]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
chore(runtime-vapor): refactor createKeyedFragment for improved insertion handling...
authoredison <daiwei521@126.com>
Tue, 21 Oct 2025 09:11:03 +0000 (17:11 +0800)
committerGitHub <noreply@github.com>
Tue, 21 Oct 2025 09:11:03 +0000 (17:11 +0800)
packages/runtime-vapor/src/apiCreateFragment.ts

index d4bb8763681979bc4155d1c563b730b8b8740c97..3e40281a0237be7420ea1bf834b2e4692c7add0e 100644 (file)
@@ -1,11 +1,31 @@
-import type { Block, BlockFn } from './block'
+import { type Block, type BlockFn, insert } from './block'
+import { advanceHydrationNode, isHydrating } from './dom/hydration'
 import { DynamicFragment } from './fragment'
+import {
+  insertionAnchor,
+  insertionParent,
+  isLastInsertion,
+  resetInsertionState,
+} from './insertionState'
 import { renderEffect } from './renderEffect'
 
 export function createKeyedFragment(key: () => any, render: BlockFn): Block {
+  const _insertionParent = insertionParent
+  const _insertionAnchor = insertionAnchor
+  const _isLastInsertion = isLastInsertion
+  if (!isHydrating) resetInsertionState()
+
   const frag = __DEV__ ? new DynamicFragment('keyed') : new DynamicFragment()
   renderEffect(() => {
     frag.update(render, key())
   })
+
+  if (!isHydrating) {
+    if (_insertionParent) insert(frag, _insertionParent, _insertionAnchor)
+  } else {
+    if (_isLastInsertion) {
+      advanceHydrationNode(_insertionParent!)
+    }
+  }
   return frag
 }