From 51914c76e859ade594c75f82e780fe5f8644c34e Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 11 Sep 2019 09:07:29 -0400 Subject: [PATCH] wip: do not fire lifecycle hooks when already unmounted --- packages/runtime-core/src/apiLifecycle.ts | 3 +++ packages/runtime-core/src/component.ts | 2 ++ packages/runtime-core/src/createRenderer.ts | 4 ++++ 3 files changed, 9 insertions(+) diff --git a/packages/runtime-core/src/apiLifecycle.ts b/packages/runtime-core/src/apiLifecycle.ts index 25bc217475..12f840f88c 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 60dfcbca6e..e09cd73d6a 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 f7eb3fc064..eea24aa33f 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) } } -- 2.47.3