Skip to content

Commit

Permalink
feat(devtools): improved KeepAlive support
Browse files Browse the repository at this point in the history
This change allows the devtools to access the cached vnodes from the KeepAlive component in order to display them as inactive in the components tree
  • Loading branch information
Akryum committed Apr 23, 2021
1 parent 060c5f1 commit 03ae300
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/runtime-core/src/components/KeepAlive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
} from '../renderer'
import { setTransitionHooks } from './BaseTransition'
import { ComponentRenderContext } from '../componentPublicInstance'
import { devtoolsComponentAdded } from '../devtools'

type MatchPattern = string | RegExp | string[] | RegExp[]

Expand Down Expand Up @@ -95,6 +96,10 @@ const KeepAliveImpl = {
const keys: Keys = new Set()
let current: VNode | null = null

if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) {
;(instance as any).__v_cache = cache
}

const parentSuspense = instance.suspense

const {
Expand Down Expand Up @@ -132,6 +137,11 @@ const KeepAliveImpl = {
invokeVNodeHook(vnodeHook, instance.parent, vnode)
}
}, parentSuspense)

if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) {
// Update components tree
devtoolsComponentAdded(instance)
}
}

sharedContext.deactivate = (vnode: VNode) => {
Expand All @@ -147,6 +157,11 @@ const KeepAliveImpl = {
}
instance.isDeactivated = true
}, parentSuspense)

if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) {
// Update components tree
devtoolsComponentAdded(instance)
}
}

function unmount(vnode: VNode) {
Expand Down

0 comments on commit 03ae300

Please sign in to comment.