mirror of https://github.com/vuejs/core.git
Merge 74ba484173
into bb4ae25793
This commit is contained in:
commit
a1b9357862
|
@ -2,7 +2,6 @@ import { warn } from '@vue/runtime-dom'
|
||||||
import {
|
import {
|
||||||
insertionAnchor,
|
insertionAnchor,
|
||||||
insertionParent,
|
insertionParent,
|
||||||
resetInsertionState,
|
|
||||||
setInsertionState,
|
setInsertionState,
|
||||||
} from '../insertionState'
|
} from '../insertionState'
|
||||||
import { child, next } from './node'
|
import { child, next } from './node'
|
||||||
|
@ -27,7 +26,7 @@ export function withHydration(container: ParentNode, fn: () => void): void {
|
||||||
isHydrating = true
|
isHydrating = true
|
||||||
setInsertionState(container, 0)
|
setInsertionState(container, 0)
|
||||||
const res = fn()
|
const res = fn()
|
||||||
resetInsertionState()
|
setInsertionState()
|
||||||
currentHydrationNode = null
|
currentHydrationNode = null
|
||||||
isHydrating = false
|
isHydrating = false
|
||||||
return res
|
return res
|
||||||
|
@ -124,6 +123,6 @@ function locateHydrationNodeImpl() {
|
||||||
warn('Hydration mismatch in ', insertionParent)
|
warn('Hydration mismatch in ', insertionParent)
|
||||||
}
|
}
|
||||||
|
|
||||||
resetInsertionState()
|
setInsertionState()
|
||||||
currentHydrationNode = node
|
currentHydrationNode = node
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,12 +5,16 @@ export let insertionAnchor: Node | 0 | undefined
|
||||||
* This function is called before a block type that requires insertion
|
* This function is called before a block type that requires insertion
|
||||||
* (component, slot outlet, if, for) is created. The state is used for actual
|
* (component, slot outlet, if, for) is created. The state is used for actual
|
||||||
* insertion on client-side render, and used for node adoption during hydration.
|
* insertion on client-side render, and used for node adoption during hydration.
|
||||||
|
*
|
||||||
|
* @returns A function that restores the previous insertion state when called.
|
||||||
*/
|
*/
|
||||||
export function setInsertionState(parent: ParentNode, anchor?: Node | 0): void {
|
export function setInsertionState(parent?: ParentNode, anchor?: Node | 0) {
|
||||||
|
const prevParent = insertionParent
|
||||||
|
const prevAnchor = insertionAnchor
|
||||||
insertionParent = parent
|
insertionParent = parent
|
||||||
insertionAnchor = anchor
|
insertionAnchor = anchor
|
||||||
}
|
return (): void => {
|
||||||
|
insertionParent = prevParent
|
||||||
export function resetInsertionState(): void {
|
insertionAnchor = prevAnchor
|
||||||
insertionParent = insertionAnchor = undefined
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue