Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions packages/runtime-core/__tests__/hydration.spec.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -699,4 +699,44 @@ describe('SSR hydration', () =>{
expect(`Hydration children mismatch`).toHaveBeenWarned()
})
})

test('sets and removes internal hydration flag', async () =>{
const checkHydration = jest.fn()

const container = document.createElement('div')
container.innerHTML = '<div>foo</div>'

const visible = ref(true)
const component = defineComponent({
render: () => h('div', 'foo'),
created(){
checkHydration(this.$.isHydrating)
},
beforeMount(){
checkHydration(this.$.isHydrating)
},
mounted(){
checkHydration(this.$.isHydrating)
}
})
const app = createSSRApp({
render: () => (visible.value ? h(component) : null)
})

app.mount(container)

visible.value = false
await nextTick()
visible.value = true
await nextTick()

expect(checkHydration.mock.calls).toMatchObject([
[true],
[true],
[true],
[false],
[false],
[false]
])
})
})
2 changes: 2 additions & 0 deletions packages/runtime-core/src/component.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -297,6 +297,7 @@ export interface ComponentInternalInstance{
isMounted: boolean
isUnmounted: boolean
isDeactivated: boolean
isHydrating: boolean
/**
* @internal
*/
Expand DownExpand Up@@ -407,6 +408,7 @@ export function createComponentInstance(
isMounted: false,
isUnmounted: false,
isDeactivated: false,
isHydrating: false,
bc: null,
c: null,
bm: null,
Expand Down
3 changes: 2 additions & 1 deletion packages/runtime-core/src/hydration.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -180,7 +180,8 @@ export function createHydrationFunctions(
parentComponent,
parentSuspense,
isSVGContainer(container),
optimized
optimized,
true
)
}
// async component
Expand Down
9 changes: 7 additions & 2 deletions packages/runtime-core/src/renderer.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -232,7 +232,8 @@ export type MountComponentFn = (
parentComponent: ComponentInternalInstance | null,
parentSuspense: SuspenseBoundary | null,
isSVG: boolean,
optimized: boolean
optimized: boolean,
hydrating?: boolean
) => void

type ProcessTextOrCommentFn = (
Expand DownExpand Up@@ -1178,14 +1179,17 @@ function baseCreateRenderer(
parentComponent,
parentSuspense,
isSVG,
optimized
optimized,
hydrating = false
) =>{
const instance: ComponentInternalInstance = (initialVNode.component = createComponentInstance(
initialVNode,
parentComponent,
parentSuspense
))

instance.isHydrating = hydrating

if (__DEV__ && instance.type.__hmrId){
registerHMR(instance)
}
Expand DownExpand Up@@ -1352,6 +1356,7 @@ function baseCreateRenderer(
if ((vnodeHook = props && props.onVnodeMounted)){
queuePostRenderEffect(() =>{
invokeVNodeHook(vnodeHook!, parent, initialVNode)
instance.isHydrating = false
}, parentSuspense)
}
// activated hook for keep-alive roots.
Expand Down