Parcourir la source

fix: KeepAlive state should be non-reactive

Evan You il y a 7 ans
Parent
commit
a428218c64
1 fichiers modifiés avec 7 ajouts et 5 suppressions
  1. 7 5
      packages/core/src/optional/keepAlive.ts

+ 7 - 5
packages/core/src/optional/keepAlive.ts

@@ -18,8 +18,13 @@ type Cache = Map<CacheKey, VNode>
 export const KeepAliveSymbol = Symbol()
 
 export class KeepAlive extends Component<KeepAliveProps> {
-  cache: Cache = new Map()
-  keys: Set<CacheKey> = new Set()
+  private cache: Cache
+  private keys: Set<CacheKey>
+
+  created() {
+    this.cache = new Map()
+    this.keys = new Set()
+  }
 
   // to be set in createRenderer when instance is created
   $unmount: (instance: ComponentInstance) => void
@@ -63,9 +68,6 @@ export class KeepAlive extends Component<KeepAliveProps> {
       }
       return children
     } else if ((vnode.flags & VNodeFlags.COMPONENT_STATEFUL) === 0) {
-      if (__DEV__) {
-        warn(`KeepAlive child must be a stateful component.`)
-      }
       return children
     }