vue3-core/packages/runtime-vapor/src/hmr.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

50 lines
1.4 KiB
TypeScript
Raw Normal View History

2024-12-08 17:20:34 +08:00
import {
currentInstance,
2024-12-08 17:20:34 +08:00
popWarningContext,
pushWarningContext,
simpleSetCurrentInstance,
2025-02-07 15:47:06 +08:00
} from '@vue/runtime-dom'
2024-12-09 20:57:40 +08:00
import { insert, normalizeBlock, remove } from './block'
2024-12-08 23:37:40 +08:00
import {
type VaporComponent,
type VaporComponentInstance,
createComponent,
devRender,
mountComponent,
unmountComponent,
} from './component'
2024-12-08 17:20:34 +08:00
export function hmrRerender(instance: VaporComponentInstance): void {
const normalized = normalizeBlock(instance.block)
const parent = normalized[0].parentNode!
const anchor = normalized[normalized.length - 1].nextSibling
remove(instance.block, parent)
const prev = currentInstance
simpleSetCurrentInstance(instance)
2024-12-08 17:20:34 +08:00
pushWarningContext(instance)
devRender(instance)
popWarningContext()
simpleSetCurrentInstance(prev, instance)
2024-12-08 17:20:34 +08:00
insert(instance.block, parent, anchor)
}
2024-12-08 21:22:51 +08:00
2024-12-08 23:37:40 +08:00
export function hmrReload(
instance: VaporComponentInstance,
newComp: VaporComponent,
): void {
const normalized = normalizeBlock(instance.block)
const parent = normalized[0].parentNode!
const anchor = normalized[normalized.length - 1].nextSibling
unmountComponent(instance, parent)
const prev = currentInstance
simpleSetCurrentInstance(instance.parent)
const newInstance = createComponent(
newComp,
instance.rawProps,
instance.rawSlots,
instance.isSingleRoot,
)
simpleSetCurrentInstance(prev, instance.parent)
mountComponent(newInstance, parent, anchor)
2024-12-08 21:22:51 +08:00
}