From: Evan You Date: Wed, 11 Sep 2019 13:07:29 +0000 (-0400) Subject: wip: do not fire lifecycle hooks when already unmounted X-Git-Tag: v3.0.0-alpha.0~786 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=51914c76e859ade594c75f82e780fe5f8644c34e;p=thirdparty%2Fvuejs%2Fcore.git wip: do not fire lifecycle hooks when already unmounted --- 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) } }