Skip to content

Commit 07b4547

Browse files
authored
chore(runtime-vapor): refactor createKeyedFragment for improved insertion handling (#14005)
1 parent ff5a06c commit 07b4547

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed
Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,31 @@
1-
import type { Block, BlockFn } from './block'
1+
import { type Block, type BlockFn, insert } from './block'
2+
import { advanceHydrationNode, isHydrating } from './dom/hydration'
23
import { DynamicFragment } from './fragment'
4+
import {
5+
insertionAnchor,
6+
insertionParent,
7+
isLastInsertion,
8+
resetInsertionState,
9+
} from './insertionState'
310
import { renderEffect } from './renderEffect'
411

512
export function createKeyedFragment(key: () => any, render: BlockFn): Block {
13+
const _insertionParent = insertionParent
14+
const _insertionAnchor = insertionAnchor
15+
const _isLastInsertion = isLastInsertion
16+
if (!isHydrating) resetInsertionState()
17+
618
const frag = __DEV__ ? new DynamicFragment('keyed') : new DynamicFragment()
719
renderEffect(() => {
820
frag.update(render, key())
921
})
22+
23+
if (!isHydrating) {
24+
if (_insertionParent) insert(frag, _insertionParent, _insertionAnchor)
25+
} else {
26+
if (_isLastInsertion) {
27+
advanceHydrationNode(_insertionParent!)
28+
}
29+
}
1030
return frag
1131
}

0 commit comments

Comments
 (0)