Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(runtime-core): do not fire lifecycle hooks during unmounting #9370

Merged
merged 11 commits into from
Jun 7, 2024
3 changes: 0 additions & 3 deletions packages/runtime-core/src/apiLifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ export function injectHook(
const wrappedHook =
hook.__weh ||
(hook.__weh = (...args: unknown[]) => {
if (target.isUnmounted) {
return
}
// disable tracking inside all lifecycle hooks
// since they can potentially be called inside effects.
pauseTracking()
Expand Down
9 changes: 7 additions & 2 deletions packages/runtime-core/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ import {
flushPostFlushCbs,
invalidateJob,
flushPreFlushCbs,
SchedulerJob
SchedulerJob,
invalidatePostJob
} from './scheduler'
import { pauseTracking, resetTracking, ReactiveEffect } from '@vue/reactivity'
import { updateProps } from './componentProps'
Expand Down Expand Up @@ -2230,7 +2231,11 @@ function baseCreateRenderer(
unregisterHMR(instance)
}

const { bum, scope, update, subTree, um } = instance
const { bum, scope, update, subTree, um, m, u } = instance

// #9264 invalidate queued lifecycle hooks
edison1105 marked this conversation as resolved.
Show resolved Hide resolved
if (m) m.forEach(invalidatePostJob)
if (u) u.forEach(invalidatePostJob)

// beforeUnmount hook
if (bum) {
Expand Down
7 changes: 7 additions & 0 deletions packages/runtime-core/src/scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ export function invalidateJob(job: SchedulerJob) {
}
}

export function invalidatePostJob(job: SchedulerJob) {
const i = pendingPostFlushCbs.indexOf(job)
if (i > postFlushIndex) {
edison1105 marked this conversation as resolved.
Show resolved Hide resolved
pendingPostFlushCbs.splice(i, 1)
}
}

export function queuePostFlushCb(cb: SchedulerJobs) {
if (!isArray(cb)) {
if (
Expand Down