diff --git a/packages/runtime-core/src/apiLifecycle.ts b/packages/runtime-core/src/apiLifecycle.ts index 25bc2174..12f840f8 100644 --- a/packages/runtime-core/src/apiLifecycle.ts +++ b/packages/runtime-core/src/apiLifecycle.ts @@ -17,6 +17,9 @@ function injectHook( ) { if (target) { ;(target[type] || (target[type] = [])).push((...args: any[]) => { + if (target.isUnmounted) { + return + } // disable tracking inside all lifecycle hooks // since they can potentially be called inside effects. pauseTracking() diff --git a/packages/runtime-core/src/component.ts b/packages/runtime-core/src/component.ts index 60dfcbca..e09cd73d 100644 --- a/packages/runtime-core/src/component.ts +++ b/packages/runtime-core/src/component.ts @@ -98,6 +98,7 @@ export interface ComponentInternalInstance { user: { [key: string]: any } // lifecycle + isUnmounted: boolean [LifecycleHooks.BEFORE_CREATE]: LifecycleHook [LifecycleHooks.CREATED]: LifecycleHook [LifecycleHooks.BEFORE_MOUNT]: LifecycleHook @@ -160,6 +161,7 @@ export function createComponentInstance( // lifecycle hooks // not using enums here because it results in computed properties + isUnmounted: false, bc: null, c: null, bm: null, diff --git a/packages/runtime-core/src/createRenderer.ts b/packages/runtime-core/src/createRenderer.ts index f7eb3fc0..eea24aa3 100644 --- a/packages/runtime-core/src/createRenderer.ts +++ b/packages/runtime-core/src/createRenderer.ts @@ -1526,6 +1526,10 @@ export function createRenderer< // unmounted hook if (um !== null) { queuePostEffect(um, parentSuspense) + // set unmounted after unmounted hooks are fired + queuePostEffect(() => { + instance.isUnmounted = true + }, parentSuspense) } }