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

Function unmount

packages/runtime-core/src/renderer.ts:2141–2267  ·  view source on GitHub ↗
(
    vnode,
    parentComponent,
    parentSuspense,
    doRemove = false,
    optimized = false,
  )

Source from the content-addressed store, hash-verified

2139 }
2140
2141 const unmount: UnmountFn = (
2142 vnode,
2143 parentComponent,
2144 parentSuspense,
2145 doRemove = false,
2146 optimized = false,
2147 ) => {
2148 const {
2149 type,
2150 props,
2151 ref,
2152 children,
2153 dynamicChildren,
2154 shapeFlag,
2155 patchFlag,
2156 dirs,
2157 cacheIndex,
2158 memo,
2159 } = vnode
2160
2161 if (patchFlag === PatchFlags.BAIL) {
2162 optimized = false
2163 }
2164
2165 // unset ref
2166 if (ref != null) {
2167 pauseTracking()
2168 setRef(ref, null, parentSuspense, vnode, true)
2169 resetTracking()
2170 }
2171
2172 // #6593 should clean memo cache when unmount
2173 if (cacheIndex != null) {
2174 parentComponent!.renderCache[cacheIndex] = undefined
2175 }
2176
2177 if (shapeFlag & ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE) {
2178 ;(parentComponent!.ctx as KeepAliveContext).deactivate(vnode)
2179 return
2180 }
2181
2182 const shouldInvokeDirs = shapeFlag & ShapeFlags.ELEMENT && dirs
2183 const shouldInvokeVnodeHook = !isAsyncWrapper(vnode)
2184
2185 let vnodeHook: VNodeHook | undefined | null
2186 if (
2187 shouldInvokeVnodeHook &&
2188 (vnodeHook = props && props.onVnodeBeforeUnmount)
2189 ) {
2190 invokeVNodeHook(vnodeHook, parentComponent, vnode)
2191 }
2192
2193 if (shapeFlag & ShapeFlags.COMPONENT) {
2194 unmountComponent(vnode.component!, parentSuspense, doRemove)
2195 } else {
2196 if (__FEATURE_SUSPENSE__ && shapeFlag & ShapeFlags.SUSPENSE) {
2197 vnode.suspense!.unmount(parentSuspense, doRemove)
2198 return

Callers 5

patchFunction · 0.70
patchKeyedChildrenFunction · 0.70
unmountComponentFunction · 0.70
unmountChildrenFunction · 0.70
renderFunction · 0.70

Calls 11

pauseTrackingFunction · 0.90
setRefFunction · 0.90
resetTrackingFunction · 0.90
isAsyncWrapperFunction · 0.90
invokeVNodeHookFunction · 0.90
invokeDirectiveHookFunction · 0.90
unmountComponentFunction · 0.85
unmountChildrenFunction · 0.85
removeMethod · 0.80
removeFunction · 0.70
unmountMethod · 0.65

Tested by

no test coverage detected