From: daiwei Date: Mon, 24 Mar 2025 09:28:11 +0000 (+0800) Subject: wip: handing teleport hmr updating X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=098f50d5a173f2ba24b1053804b675c1eb1cc8a8;p=thirdparty%2Fvuejs%2Fcore.git wip: handing teleport hmr updating --- diff --git a/packages/runtime-vapor/src/component.ts b/packages/runtime-vapor/src/component.ts index 7989b67a8b..2855fa9ce9 100644 --- a/packages/runtime-vapor/src/component.ts +++ b/packages/runtime-vapor/src/component.ts @@ -172,6 +172,13 @@ export function createComponent( frag.hydrate() } + if (__DEV__) { + const instance = currentInstance as VaporComponentInstance + ;(instance!.hmrEffects || (instance!.hmrEffects = [])).push(() => + frag.remove(frag.anchor.parentNode!), + ) + } + return frag as any } @@ -389,6 +396,7 @@ export class VaporComponentInstance implements GenericComponentInstance { devtoolsRawSetupState?: any hmrRerender?: () => void hmrReload?: (newComp: VaporComponent) => void + hmrEffects?: (() => void)[] propsOptions?: NormalizedPropsOptions emitsOptions?: ObjectEmitsOptions | null isSingleRoot?: boolean diff --git a/packages/runtime-vapor/src/hmr.ts b/packages/runtime-vapor/src/hmr.ts index 741f385861..c960a2610c 100644 --- a/packages/runtime-vapor/src/hmr.ts +++ b/packages/runtime-vapor/src/hmr.ts @@ -19,6 +19,10 @@ export function hmrRerender(instance: VaporComponentInstance): void { const parent = normalized[0].parentNode! const anchor = normalized[normalized.length - 1].nextSibling remove(instance.block, parent) + if (instance.hmrEffects) { + instance.hmrEffects.forEach(e => e()) + instance.hmrEffects.length = 0 + } const prev = currentInstance simpleSetCurrentInstance(instance) pushWarningContext(instance) @@ -36,6 +40,10 @@ export function hmrReload( const parent = normalized[0].parentNode! const anchor = normalized[normalized.length - 1].nextSibling unmountComponent(instance, parent) + if (instance.hmrEffects) { + instance.hmrEffects.forEach(e => e()) + instance.hmrEffects.length = 0 + } const prev = currentInstance simpleSetCurrentInstance(instance.parent) const newInstance = createComponent(