@@ -43,7 +43,6 @@ export interface KeepAliveInstance extends VaporComponentInstance {
4343 anchor ?: Node | null | 0 ,
4444 ) => void
4545 deactivate : ( instance : VaporComponentInstance ) => void
46- cacheComponent : ( instance : VaporComponentInstance ) => void
4746 getCachedComponent : (
4847 comp : VaporComponent ,
4948 ) => VaporComponentInstance | VaporFragment | undefined
@@ -82,14 +81,6 @@ export const VaporKeepAliveImpl: ObjectVaporComponent = defineVaporComponent({
8281
8382 keepAliveInstance . getCachedComponent = comp => cache . get ( comp )
8483
85- keepAliveInstance . cacheComponent = ( instance : VaporComponentInstance ) => {
86- if ( ! shouldCache ( instance as GenericComponentInstance , props ) ) {
87- return
88- }
89- instance . shapeFlag ! |= ShapeFlags . COMPONENT_SHOULD_KEEP_ALIVE
90- innerCacheBlock ( instance . type , instance )
91- }
92-
9384 keepAliveInstance . activate = ( instance , parentNode , anchor ) => {
9485 current = instance
9586 activate ( instance , parentNode , anchor )
@@ -241,28 +232,18 @@ export const VaporKeepAliveImpl: ObjectVaporComponent = defineVaporComponent({
241232 return children
242233 }
243234
244- // process shapeFlag
245- if ( isVaporComponent ( children ) ) {
246- children . shapeFlag ! |= ShapeFlags . COMPONENT_SHOULD_KEEP_ALIVE
247- } else if ( isInteropFragment ( children ) ) {
248- children . vnode ! . shapeFlag ! |= ShapeFlags . COMPONENT_SHOULD_KEEP_ALIVE
249- } else if ( isDynamicFragment ( children ) ) {
250- processFragment ( children )
251-
252- // re-process fragment when fragment updates
253- ; ( children . beforeTeardown || ( children . beforeTeardown = [ ] ) ) . push (
235+ const injectKeepAliveHooks = ( frag : DynamicFragment ) => {
236+ ; ( frag . beforeTeardown || ( frag . beforeTeardown = [ ] ) ) . push (
254237 ( oldKey , nodes , scope ) => {
255- processFragment ( children )
238+ processFragment ( frag )
256239 keptAliveScopes . set ( oldKey , scope )
257240 return true
258241 } ,
259242 )
260- ; ( children . beforeMount || ( children . beforeMount = [ ] ) ) . push ( ( ) =>
261- cacheFragment ( children ) ,
243+ ; ( frag . beforeMount || ( frag . beforeMount = [ ] ) ) . push ( ( ) =>
244+ cacheFragment ( frag ) ,
262245 )
263-
264- // get scope for fragment
265- children . getScope = key => {
246+ frag . getScope = key => {
266247 const scope = keptAliveScopes . get ( key )
267248 if ( scope ) {
268249 keptAliveScopes . delete ( key )
@@ -271,6 +252,22 @@ export const VaporKeepAliveImpl: ObjectVaporComponent = defineVaporComponent({
271252 }
272253 }
273254
255+ // process shapeFlag
256+ if ( isVaporComponent ( children ) ) {
257+ children . shapeFlag ! |= ShapeFlags . COMPONENT_SHOULD_KEEP_ALIVE
258+ if ( isAsyncWrapper ( children ) ) {
259+ injectKeepAliveHooks ( children . block as DynamicFragment )
260+ }
261+ } else if ( isInteropFragment ( children ) ) {
262+ children . vnode ! . shapeFlag ! |= ShapeFlags . COMPONENT_SHOULD_KEEP_ALIVE
263+ } else if ( isDynamicFragment ( children ) ) {
264+ processFragment ( children )
265+ injectKeepAliveHooks ( children )
266+ if ( isVaporComponent ( children . nodes ) && isAsyncWrapper ( children . nodes ) ) {
267+ injectKeepAliveHooks ( children . nodes . block as DynamicFragment )
268+ }
269+ }
270+
274271 return children
275272 } ,
276273} )
@@ -287,10 +284,9 @@ const shouldCache = (
287284 : ( block as GenericComponentInstance ) . type
288285 ) as GenericComponent & AsyncComponentInternalOptions
289286
290- // For unresolved async wrappers, skip caching
291- // Wait for resolution and re-process in createInnerComp
287+ // always cache unresolved async components
292288 if ( isAsync && ! type . __asyncResolved ) {
293- return false
289+ return true
294290 }
295291
296292 const { include, exclude } = props
0 commit comments