@@ -128,7 +128,7 @@ export const VaporKeepAliveImpl: ObjectVaporComponent = defineVaporComponent({
128128      if  ( isFragment ( block )  &&  ( frag  =  findInteropFragment ( block ) ) )  { 
129129        // vdom component: cache the fragment 
130130        toCache  =  frag 
131-         key  =  getCacheKey ( frag ) 
131+         key  =  frag . vnode ! . type 
132132      }  else  { 
133133        // vapor component: cache the instance 
134134        toCache  =  innerBlock 
@@ -150,7 +150,9 @@ export const VaporKeepAliveImpl: ObjectVaporComponent = defineVaporComponent({
150150
151151        // current instance will be unmounted as part of keep-alive's unmount 
152152        if  ( current )  { 
153-           const  currentKey  =  getCacheKey ( current ) 
153+           const  currentKey  =  isVaporComponent ( current ) 
154+             ? current . type 
155+             : current . vnode ! . type 
154156          if  ( currentKey  ===  key )  { 
155157            // call deactivated hook 
156158            const  da  =  instance . da 
@@ -166,29 +168,12 @@ export const VaporKeepAliveImpl: ObjectVaporComponent = defineVaporComponent({
166168    keepAliveInstance . getStorageContainer  =  ( )  =>  storageContainer 
167169
168170    keepAliveInstance . getCachedComponent  =  comp  =>  { 
169-       // For async components, use the resolved component type as the cache key 
170-       return  cache . get ( comp . __asyncResolved  ||  comp ) 
171-     } 
172- 
173-     const  setShapeFlags  =  ( instance : VaporComponentInstance )  =>  { 
174-       // For unresolved async wrappers, skip processing 
175-       // Wait for resolution and re-process via createInnerComp 
176-       if  ( isAsyncWrapper ( instance )  &&  ! instance . type . __asyncResolved )  { 
177-         return 
178-       } 
179- 
180-       if  ( cache . has ( instance . type ) )  { 
181-         instance . shapeFlag !  |=  ShapeFlags . COMPONENT_KEPT_ALIVE 
182-       } 
183- 
184-       if  ( shouldCache ( instance ) )  { 
185-         instance . shapeFlag !  |=  ShapeFlags . COMPONENT_SHOULD_KEEP_ALIVE 
186-       } 
171+       return  cache . get ( comp ) 
187172    } 
188173
189174    keepAliveInstance . cacheComponent  =  ( instance : VaporComponentInstance )  =>  { 
190175      if  ( ! shouldCache ( instance ) )  return 
191-       setShapeFlags ( instance ) 
176+       instance . shapeFlag !   |=   ShapeFlags . COMPONENT_SHOULD_KEEP_ALIVE 
192177      innerCacheBlock ( instance . type ,  instance ) 
193178    } 
194179
@@ -198,14 +183,23 @@ export const VaporKeepAliveImpl: ObjectVaporComponent = defineVaporComponent({
198183
199184      const  fragment  =  findInteropFragment ( frag . nodes ) 
200185      if  ( fragment )  { 
201-         setVdomShapeFlags ( fragment ) 
186+         if  ( cache . has ( fragment . vnode ! . type ) )  { 
187+           fragment . vnode ! . shapeFlag !  |=  ShapeFlags . COMPONENT_KEPT_ALIVE 
188+         } 
189+         if  ( shouldCache ( innerBlock ) )  { 
190+           fragment . vnode ! . shapeFlag !  |=  ShapeFlags . COMPONENT_SHOULD_KEEP_ALIVE 
191+         } 
202192      }  else  { 
203-         setShapeFlags ( innerBlock ) 
193+         if  ( cache . has ( innerBlock . type ) )  { 
194+           innerBlock . shapeFlag !  |=  ShapeFlags . COMPONENT_KEPT_ALIVE 
195+         } 
196+         if  ( shouldCache ( innerBlock ) )  { 
197+           innerBlock . shapeFlag !  |=  ShapeFlags . COMPONENT_SHOULD_KEEP_ALIVE 
198+         } 
204199      } 
205200    } 
206201
207202    keepAliveInstance . cacheFragment  =  ( fragment : DynamicFragment )  =>  { 
208-       // Find the component within the fragment 
209203      const  innerBlock  =  getInnerBlock ( fragment . nodes ) 
210204      if  ( ! innerBlock  ||  ! shouldCache ( innerBlock ) )  return 
211205
@@ -216,12 +210,11 @@ export const VaporKeepAliveImpl: ObjectVaporComponent = defineVaporComponent({
216210      // find vdom interop fragment 
217211      const  frag  =  findInteropFragment ( fragment ) 
218212      if  ( frag )  { 
219-         // For vdom components, set shapeFlag 
220-         setVdomShapeFlags ( frag ) 
213+         frag . vnode ! . shapeFlag !  |=  ShapeFlags . COMPONENT_SHOULD_KEEP_ALIVE 
221214        toCache  =  frag 
222-         key  =  getCacheKey ( frag ) ! 
215+         key  =  frag . vnode ! . type 
223216      }  else  { 
224-         setShapeFlags ( innerBlock ) 
217+         innerBlock . shapeFlag !   |=   ShapeFlags . COMPONENT_SHOULD_KEEP_ALIVE 
225218        toCache  =  innerBlock 
226219        key  =  innerBlock . type 
227220      } 
@@ -238,24 +231,6 @@ export const VaporKeepAliveImpl: ObjectVaporComponent = defineVaporComponent({
238231      deactivate ( instance ,  storageContainer ) 
239232    } 
240233
241-     function  setVdomShapeFlags ( 
242-       fragment : VaporFragment , 
243-       shouldKeepAlive : boolean  =  true , 
244-     )  { 
245-       if  ( shouldKeepAlive )  { 
246-         fragment . vnode ! . shapeFlag !  |=  ShapeFlags . COMPONENT_SHOULD_KEEP_ALIVE 
247-       } 
248-       const  fragKey  =  getCacheKey ( fragment ) 
249-       if  ( fragKey  &&  cache . has ( fragKey ) )  { 
250-         fragment . vnode ! . shapeFlag !  |=  ShapeFlags . COMPONENT_KEPT_ALIVE 
251-       } 
252-       // Also set shapeFlag on the component instance if it exists 
253-       const  vnode  =  fragment . vnode  as  any 
254-       if  ( vnode  &&  vnode . component )  { 
255-         vnode . component . shapeFlag  =  fragment . vnode ! . shapeFlag 
256-       } 
257-     } 
258- 
259234    function  resetCachedShapeFlag ( 
260235      cached : VaporComponentInstance  |  VaporFragment , 
261236    )  { 
@@ -277,9 +252,9 @@ export const VaporKeepAliveImpl: ObjectVaporComponent = defineVaporComponent({
277252    // Process shapeFlag for vapor and vdom components 
278253    // DynamicFragment (v-if, <component is/>) is processed in DynamicFragment.update 
279254    if  ( isVaporComponent ( children ) )  { 
280-       setShapeFlags ( children ) 
255+       children . shapeFlag !   |=   ShapeFlags . COMPONENT_SHOULD_KEEP_ALIVE 
281256    }  else  if  ( isInteropFragment ( children ) )  { 
282-       setVdomShapeFlags ( children ,   true ) 
257+       children . vnode ! . shapeFlag !   |=   ShapeFlags . COMPONENT_SHOULD_KEEP_ALIVE 
283258    } 
284259
285260    function  pruneCache ( filter : ( name : string )  =>  boolean )  { 
@@ -324,11 +299,9 @@ export const VaporKeepAliveImpl: ObjectVaporComponent = defineVaporComponent({
324299function  getInnerBlock ( block : Block ) : VaporComponentInstance  |  undefined  { 
325300  if  ( isVaporComponent ( block ) )  { 
326301    return  block 
327-   } 
328-   if  ( isInteropFragment ( block ) )  { 
302+   }  else  if  ( isInteropFragment ( block ) )  { 
329303    return  block . vnode  as  any 
330-   } 
331-   if  ( isFragment ( block ) )  { 
304+   }  else  if  ( isFragment ( block ) )  { 
332305    return  getInnerBlock ( block . nodes ) 
333306  } 
334307} 
@@ -356,15 +329,6 @@ function getInstanceFromCache(
356329  return  cached . vnode ! . component  as  GenericComponentInstance 
357330} 
358331
359- function  getCacheKey ( block : VaporComponentInstance  |  VaporFragment ) : CacheKey  { 
360-   if  ( isVaporComponent ( block ) )  { 
361-     return  block . type 
362-   } 
363- 
364-   // vdom interop 
365-   return  block . vnode ! . type 
366- } 
367- 
368332export  function  activate ( 
369333  instance : VaporComponentInstance , 
370334  parentNode : ParentNode , 
0 commit comments