wip: do not fire lifecycle hooks when already unmounted
This commit is contained in:
parent
6bc368b2b6
commit
51914c76e8
@ -17,6 +17,9 @@ function injectHook(
|
|||||||
) {
|
) {
|
||||||
if (target) {
|
if (target) {
|
||||||
;(target[type] || (target[type] = [])).push((...args: any[]) => {
|
;(target[type] || (target[type] = [])).push((...args: any[]) => {
|
||||||
|
if (target.isUnmounted) {
|
||||||
|
return
|
||||||
|
}
|
||||||
// disable tracking inside all lifecycle hooks
|
// disable tracking inside all lifecycle hooks
|
||||||
// since they can potentially be called inside effects.
|
// since they can potentially be called inside effects.
|
||||||
pauseTracking()
|
pauseTracking()
|
||||||
|
@ -98,6 +98,7 @@ export interface ComponentInternalInstance {
|
|||||||
user: { [key: string]: any }
|
user: { [key: string]: any }
|
||||||
|
|
||||||
// lifecycle
|
// lifecycle
|
||||||
|
isUnmounted: boolean
|
||||||
[LifecycleHooks.BEFORE_CREATE]: LifecycleHook
|
[LifecycleHooks.BEFORE_CREATE]: LifecycleHook
|
||||||
[LifecycleHooks.CREATED]: LifecycleHook
|
[LifecycleHooks.CREATED]: LifecycleHook
|
||||||
[LifecycleHooks.BEFORE_MOUNT]: LifecycleHook
|
[LifecycleHooks.BEFORE_MOUNT]: LifecycleHook
|
||||||
@ -160,6 +161,7 @@ export function createComponentInstance(
|
|||||||
|
|
||||||
// lifecycle hooks
|
// lifecycle hooks
|
||||||
// not using enums here because it results in computed properties
|
// not using enums here because it results in computed properties
|
||||||
|
isUnmounted: false,
|
||||||
bc: null,
|
bc: null,
|
||||||
c: null,
|
c: null,
|
||||||
bm: null,
|
bm: null,
|
||||||
|
@ -1526,6 +1526,10 @@ export function createRenderer<
|
|||||||
// unmounted hook
|
// unmounted hook
|
||||||
if (um !== null) {
|
if (um !== null) {
|
||||||
queuePostEffect(um, parentSuspense)
|
queuePostEffect(um, parentSuspense)
|
||||||
|
// set unmounted after unmounted hooks are fired
|
||||||
|
queuePostEffect(() => {
|
||||||
|
instance.isUnmounted = true
|
||||||
|
}, parentSuspense)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user