]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
wip: handing teleport hmr updating
authordaiwei <daiwei521@126.com>
Mon, 24 Mar 2025 09:28:11 +0000 (17:28 +0800)
committerdaiwei <daiwei521@126.com>
Mon, 24 Mar 2025 09:28:11 +0000 (17:28 +0800)
packages/runtime-vapor/src/component.ts
packages/runtime-vapor/src/hmr.ts

index 7989b67a8b6bde20f21e822f316e13e3610a137b..2855fa9ce9658093ae22aa27e7cdb0634bc857b7 100644 (file)
@@ -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
index 741f385861db5efe5eb40f569f8f37596c541971..c960a2610cf8b065e6aba5eee263d8c2645a2de5 100644 (file)
@@ -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(