diff --git a/packages/core/src/optional/keepAlive.ts b/packages/core/src/optional/keepAlive.ts index 29386e7c..bd5e3355 100644 --- a/packages/core/src/optional/keepAlive.ts +++ b/packages/core/src/optional/keepAlive.ts @@ -16,19 +16,12 @@ type Cache = Map export const KeepAliveSymbol = Symbol() export class KeepAlive extends Component<{}, KeepAliveProps> { - cache: Cache - keys: Set + cache: Cache = new Map() + keys: Set = new Set() // to be set in createRenderer when instance is created $unmount: (instance: MountedComponent) => void - created() { - this.cache = new Map() - // keys represents the "freshness" of cached components - // oldest cached ones will be pruned first when cache count exceeds max - this.keys = new Set() - } - beforeUnmount() { this.cache.forEach(vnode => { // change flag so it can be properly unmounted