MCPcopy
hub / github.com/vuejs/core / unmountComponent

Function unmountComponent

packages/runtime-core/src/renderer.ts:2333–2388  ·  view source on GitHub ↗
(
    instance: ComponentInternalInstance,
    parentSuspense: SuspenseBoundary | null,
    doRemove?: boolean,
  )

Source from the content-addressed store, hash-verified

2331 }
2332
2333 const unmountComponent = (
2334 instance: ComponentInternalInstance,
2335 parentSuspense: SuspenseBoundary | null,
2336 doRemove?: boolean,
2337 ) => {
2338 if (__DEV__ && instance.type.__hmrId) {
2339 unregisterHMR(instance)
2340 }
2341
2342 const { bum, scope, job, subTree, um, m, a } = instance
2343 invalidateMount(m)
2344 invalidateMount(a)
2345
2346 // beforeUnmount hook
2347 if (bum) {
2348 invokeArrayFns(bum)
2349 }
2350
2351 if (
2352 __COMPAT__ &&
2353 isCompatEnabled(DeprecationTypes.INSTANCE_EVENT_HOOKS, instance)
2354 ) {
2355 instance.emit('hook:beforeDestroy')
2356 }
2357
2358 // stop effects in component scope
2359 scope.stop()
2360
2361 // job may be null if a component is unmounted before its async
2362 // setup has resolved.
2363 if (job) {
2364 // so that scheduler will no longer invoke it
2365 job.flags! |= SchedulerJobFlags.DISPOSED
2366 unmount(subTree, instance, parentSuspense, doRemove)
2367 }
2368 // unmounted hook
2369 if (um) {
2370 queuePostRenderEffect(um, parentSuspense)
2371 }
2372 if (
2373 __COMPAT__ &&
2374 isCompatEnabled(DeprecationTypes.INSTANCE_EVENT_HOOKS, instance)
2375 ) {
2376 queuePostRenderEffect(
2377 () => instance.emit('hook:destroyed'),
2378 parentSuspense,
2379 )
2380 }
2381 queuePostRenderEffect(() => {
2382 instance.isUnmounted = true
2383 }, parentSuspense)
2384
2385 if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) {
2386 devtoolsComponentRemoved(instance)
2387 }
2388 }
2389
2390 const unmountChildren: UnmountChildrenFn = (

Callers 1

unmountFunction · 0.85

Calls 7

unregisterHMRFunction · 0.90
invokeArrayFnsFunction · 0.90
isCompatEnabledFunction · 0.90
devtoolsComponentRemovedFunction · 0.90
invalidateMountFunction · 0.85
unmountFunction · 0.70
stopMethod · 0.45

Tested by

no test coverage detected