]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
wip: do not fire lifecycle hooks when already unmounted
authorEvan You <yyx990803@gmail.com>
Wed, 11 Sep 2019 13:07:29 +0000 (09:07 -0400)
committerEvan You <yyx990803@gmail.com>
Wed, 11 Sep 2019 15:10:13 +0000 (11:10 -0400)
packages/runtime-core/src/apiLifecycle.ts
packages/runtime-core/src/component.ts
packages/runtime-core/src/createRenderer.ts

index 25bc217475e8860996f561a977ed80de0e0732b4..12f840f88c6fd5a619751108c29268f5be94b389 100644 (file)
@@ -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()
index 60dfcbca6e34a9a3f074458a7a6d318bcc657829..e09cd73d6abb759ad0611617831a9013fb28247c 100644 (file)
@@ -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,
index f7eb3fc064bb2aa4a945bf92ffac0235e65532b7..eea24aa33fadcaec771736136a968438a09c4eb0 100644 (file)
@@ -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)
     }
   }