expect(container.innerHTML).toBe(`<!--${anchorLabel}-->`)
})
+ test('consecutive if node', async () => {
+ const data = ref(true)
+ const { container } = await testHydration(
+ `<template>
+ <components.Child v-if="data"/>
+ </template>`,
+ { Child: `<template><div v-if="data">foo</div></template>` },
+ data,
+ )
+ expect(container.innerHTML).toBe(`<div>foo</div><!--if--><!--if-->`)
+
+ data.value = false
+ await nextTick()
+ expect(container.innerHTML).toBe(`<!--if-->`)
+
+ data.value = true
+ await nextTick()
+ expect(container.innerHTML).toBe(`<div>foo</div><!--if--><!--if-->`)
+ })
+
test('v-if/else-if/else chain on component - switch branches', async () => {
const data = ref('a')
const { container } = await testHydration(
currentHydrationNode = node
}
+export function advanceHydrationNode(node: Node): void {
+ setCurrentHydrationNode(node.nextSibling || node.parentNode)
+}
+
let isOptimized = false
function performHydration<T>(
}
}
- currentHydrationNode = __next(node)
+ advanceHydrationNode(node)
return node
}
export function locateVaporFragmentAnchor(
node: Node,
anchorLabel: string,
-): Comment | undefined {
- let n = node.nextSibling
- while (n) {
- if (isComment(n, anchorLabel)) return n
- n = n.nextSibling
+): Comment | null {
+ while (node) {
+ if (isComment(node, anchorLabel)) return node
+ node = node.nextSibling!
}
+ return null
}
export function isEmptyTextNode(node: Node): node is Text {
} from './block'
import type { TransitionHooks } from '@vue/runtime-dom'
import {
+ advanceHydrationNode,
currentHydrationNode,
isComment,
isHydrating,
locateHydrationNode,
locateVaporFragmentAnchor,
- setCurrentHydrationNode,
} from './dom/hydration'
import {
applyTransitionHooks,
*/
forwarded?: boolean
teardown?: () => void
+ anchorLabel?: string
constructor(anchorLabel?: string) {
super([])
if (isHydrating) {
locateHydrationNode(anchorLabel === 'slot')
- this.hydrate(anchorLabel!)
+ this.anchorLabel = anchorLabel
} else {
this.anchor =
__DEV__ && anchorLabel ? createComment(anchorLabel) : createTextNode()
update(render?: BlockFn, key: any = render): void {
if (key === this.current) {
+ if (isHydrating) this.hydrate(this.anchorLabel!)
return
}
this.current = key
const prevSub = setActiveSub()
- const parent = this.anchor.parentNode
+ const parent = isHydrating ? null : this.anchor.parentNode
const transition = this.$transition
const renderBranch = () => {
if (render) {
}
}
- if (isHydrating) {
- setCurrentHydrationNode(this.anchor.nextSibling)
- }
setActiveSub(prevSub)
+ if (isHydrating) this.hydrate(this.anchorLabel!)
}
hydrate(label: string): void {
throw new Error(`${label} fragment anchor node was not found.`)
}
}
+ advanceHydrationNode(this.anchor)
}
}