Skip to content

Commit 7c1e665

Browse files
committed
wip: root instance $destroy before $mount
1 parent 4d62670 commit 7c1e665

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

packages/runtime-core/src/compat/global.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
isReactive,
33
reactive,
4+
stop,
45
track,
56
TrackOpTypes,
67
trigger,
@@ -13,7 +14,8 @@ import {
1314
EMPTY_OBJ,
1415
isArray,
1516
isObject,
16-
isString
17+
isString,
18+
invokeArrayFns
1719
} from '@vue/shared'
1820
import { warn } from '../warning'
1921
import { cloneVNode, createVNode } from '../vnode'
@@ -467,8 +469,28 @@ export function installCompatMount(
467469
devtoolsUnmountApp(app)
468470
}
469471
delete app._container.__vue_app__
470-
} else if (__DEV__) {
471-
warn(`Cannot unmount an app that is not mounted.`)
472+
} else {
473+
const { bum, effects, um } = instance
474+
// beforeDestroy hooks
475+
if (bum) {
476+
invokeArrayFns(bum)
477+
}
478+
if (isCompatEnabled(DeprecationTypes.INSTANCE_EVENT_HOOKS, instance)) {
479+
instance.emit('hook:beforeDestroy')
480+
}
481+
// stop effects
482+
if (effects) {
483+
for (let i = 0; i < effects.length; i++) {
484+
stop(effects[i])
485+
}
486+
}
487+
// unmounted hook
488+
if (um) {
489+
invokeArrayFns(um)
490+
}
491+
if (isCompatEnabled(DeprecationTypes.INSTANCE_EVENT_HOOKS, instance)) {
492+
instance.emit('hook:destroyed')
493+
}
472494
}
473495
}
474496

0 commit comments

Comments
 (0)