isHydrating,
locateHydrationNode,
locateVaporFragmentAnchor,
- updateNextChildToHydrate,
} from './dom/hydration'
import { ForFragment, VaporFragment } from './fragment'
import {
// useSelector only
let currentKey: any
let parentAnchor: Node
- if (isHydrating) {
- parentAnchor =
- locateVaporFragmentAnchor(currentHydrationNode!, FOR_ANCHOR_LABEL) ||
- // fallback to the fragment end anchor if in ssr slots vnode fallback
- locateVaporFragmentAnchor(currentHydrationNode!, ']')!
- if (__DEV__ && !parentAnchor) {
- // this should not happen
- throw new Error(`v-for fragment anchor node was not found.`)
- }
- } else {
+ if (!isHydrating) {
parentAnchor = __DEV__ ? createComment('for') : createTextNode()
}
if (!isMounted) {
isMounted = true
for (let i = 0; i < newLength; i++) {
- // TODO add tests
- if (isHydrating && i > 0 && _insertionParent) {
- updateNextChildToHydrate(_insertionParent)
- }
mount(source, i)
}
+
+ if (isHydrating) {
+ parentAnchor =
+ locateVaporFragmentAnchor(currentHydrationNode!, FOR_ANCHOR_LABEL) ||
+ // fallback to the fragment end anchor if in ssr slots vnode fallback
+ locateVaporFragmentAnchor(currentHydrationNode!, ']')!
+ if (__DEV__ && !parentAnchor) {
+ // this should not happen
+ throw new Error(`v-for fragment anchor node was not found.`)
+ }
+ }
} else {
parent = parent || parentAnchor!.parentNode
if (!oldLength) {
}
if (isHydrating) {
advanceHydrationNode(
- _insertionAnchor !== undefined ? _insertionParent! : parentAnchor,
+ _insertionAnchor !== undefined ? _insertionParent! : parentAnchor!,
)
}
}
export let adoptTemplate: (node: Node, template: string) => Node | null
-export let locateHydrationNode: (isFragment?: boolean) => void
+export let locateHydrationNode: () => void
type Anchor = Comment & {
// cached matching fragment end to avoid repeated traversal
return node
}
-const childToHydrateMap = new WeakMap<ParentNode, Node>()
-
-export function updateNextChildToHydrate(parent: ParentNode): void {
- let nextNode = childToHydrateMap.get(parent)
- if (nextNode) {
- nextNode = __next(nextNode)
- if (nextNode) {
- childToHydrateMap.set(parent, (currentHydrationNode = nextNode))
- }
- }
-}
-
-function locateHydrationNodeImpl(isFragment?: boolean): void {
+function locateHydrationNodeImpl(): void {
let node: Node | null
// prepend / firstChild
if (insertionAnchor === 0) {
} else {
node = currentHydrationNode
if (insertionParent && (!node || node.parentNode !== insertionParent)) {
- node =
- childToHydrateMap.get(insertionParent) ||
- __nthChild(insertionParent, insertionParent.$dp || 0)
- }
-
- // locate slot fragment start anchor
- // if (isFragment && node && !isComment(node, '[')) {
- // node = locateVaporFragmentAnchor(node, '[')!
- // } else {
- // while (node && isNonHydrationNode(node)) {
- // node = node.nextSibling!
- // }
- // }
-
- if (insertionParent && node) {
- const nextNode = node.nextSibling
- if (nextNode) childToHydrateMap.set(insertionParent, nextNode)
+ node = __nthChild(insertionParent, insertionParent.$dp || 0)
}
}