Skip to content

Commit 78ac66e

Browse files
committed
wip: revert consumeFragmentStart changes
1 parent 4a0fa08 commit 78ac66e

File tree

4 files changed

+21
-34
lines changed

4 files changed

+21
-34
lines changed

packages/runtime-vapor/src/apiCreateDynamicComponent.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,8 @@ import {
2626
} from './insertionState'
2727
import {
2828
advanceHydrationNode,
29-
currentHydrationNode,
30-
isComment,
3129
isHydrating,
3230
locateHydrationNode,
33-
setCurrentHydrationNode,
3431
} from './dom/hydration'
3532
import { DynamicFragment, type VaporFragment } from './fragment'
3633
import type { KeepAliveInstance } from './components/KeepAlive'
@@ -73,11 +70,7 @@ export function createDynamicComponent(
7370

7471
const frag = appContext.vapor.vdomMountVNode(value, currentInstance)
7572
if (isHydrating) {
76-
const consumeFragmentStart = shouldConsumeFragmentStart(value)
77-
locateHydrationNode()
78-
if (consumeFragmentStart && isComment(currentHydrationNode!, '[')) {
79-
setCurrentHydrationNode(currentHydrationNode!.nextSibling)
80-
}
73+
locateHydrationNode(shouldConsumeFragmentStart(value))
8174
frag.hydrate()
8275
if (_isLastInsertion) {
8376
advanceHydrationNode(_insertionParent!)

packages/runtime-vapor/src/apiCreateFor.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,7 @@ export const createFor = (
7979
const _insertionIndex = insertionIndex
8080
const _isLastInsertion = isLastInsertion
8181
if (isHydrating) {
82-
locateHydrationNode()
83-
if (isComment(currentHydrationNode!, '[')) {
84-
setCurrentHydrationNode(currentHydrationNode!.nextSibling)
85-
}
82+
locateHydrationNode(true)
8683
} else {
8784
resetInsertionState()
8885
}

packages/runtime-vapor/src/apiCreateIf.ts

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import { type Block, type BlockFn, insert } from './block'
22
import {
33
advanceHydrationNode,
4-
currentHydrationNode,
5-
isComment,
64
isHydrating,
75
locateHydrationNode,
8-
setCurrentHydrationNode,
96
} from './dom/hydration'
107
import {
118
insertionAnchor,
@@ -35,12 +32,9 @@ export function createIf(
3532
if (once) {
3633
const ok = condition()
3734
if (isHydrating) {
38-
const consumeFragmentStart =
39-
decodeIfShape(blockShape!, ok) === VaporBlockShape.MULTI_ROOT
40-
locateHydrationNode()
41-
if (consumeFragmentStart && isComment(currentHydrationNode!, '[')) {
42-
setCurrentHydrationNode(currentHydrationNode!.nextSibling)
43-
}
35+
locateHydrationNode(
36+
decodeIfShape(blockShape!, ok) === VaporBlockShape.MULTI_ROOT,
37+
)
4438
}
4539
frag = ok
4640
? b1()
@@ -57,12 +51,9 @@ export function createIf(
5751
renderEffect(() => {
5852
const ok = condition()
5953
if (isHydrating) {
60-
const consumeFragmentStart =
61-
decodeIfShape(blockShape!, ok) === VaporBlockShape.MULTI_ROOT
62-
locateHydrationNode()
63-
if (consumeFragmentStart && isComment(currentHydrationNode!, '[')) {
64-
setCurrentHydrationNode(currentHydrationNode!.nextSibling)
65-
}
54+
locateHydrationNode(
55+
decodeIfShape(blockShape!, ok) === VaporBlockShape.MULTI_ROOT,
56+
)
6657
}
6758
;(frag as DynamicFragment).update(
6859
ok ? b1 : b2,

packages/runtime-vapor/src/dom/hydration.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ export function enterHydration(node: Node): () => void {
207207
}
208208

209209
export let adoptTemplate: (node: Node, template: string) => Node | null
210-
export let locateHydrationNode: () => void
210+
export let locateHydrationNode: (consumeFragmentStart?: boolean) => void
211211

212212
type Anchor = Node & {
213213
// Runtime-created or reused preserve anchor that must stay in place during
@@ -280,7 +280,7 @@ export function locateNextNode(node: Node): Node | null {
280280
: _next(node)
281281
}
282282

283-
function locateHydrationNodeImpl() {
283+
function locateHydrationNodeImpl(consumeFragmentStart = false) {
284284
let node: Node | null
285285

286286
if (insertionIndex !== undefined) {
@@ -293,6 +293,11 @@ function locateHydrationNodeImpl() {
293293
node = currentHydrationNode
294294
}
295295

296+
// consume fragment start anchor if needed
297+
if (consumeFragmentStart && node && isComment(node, '[')) {
298+
node = node.nextSibling
299+
}
300+
296301
if (__DEV__ && !node) {
297302
throw new Error(
298303
`No current hydration node was found.\n` +
@@ -379,12 +384,13 @@ function handleMismatch(node: Node, template: string): Node {
379384
removeFragmentNodes(node)
380385
}
381386

382-
// Range-end markers and preserve anchors are structural boundaries, not
383-
// replaceable content. New nodes must be inserted before them.
384-
const shouldInsertBefore = isHydrationAnchor(node)
387+
// Reused hydration anchors are structural boundaries, not replaceable
388+
// content. Mismatch recovery inserts the new node before the anchor and
389+
// keeps the anchor in place.
390+
const shouldPreserveAnchor = isHydrationAnchor(node)
385391
const container = parentNode(node)!
386-
const next = shouldInsertBefore ? node : _next(node)
387-
if (!shouldInsertBefore) {
392+
const next = shouldPreserveAnchor ? node : _next(node)
393+
if (!shouldPreserveAnchor) {
388394
remove(node, container)
389395
}
390396

0 commit comments

Comments
 (0)