|
|
@@ -384,9 +384,13 @@ const VaporKeepAliveImpl = defineVaporComponent({
|
|
|
const prevCtx = setCurrentKeepAliveCtx(keepAliveCtx)
|
|
|
let children = slots.default()
|
|
|
setCurrentKeepAliveCtx(prevCtx)
|
|
|
+ registerDynamicFragmentUpdated(children, cacheBlock)
|
|
|
|
|
|
if (isArray(children)) {
|
|
|
children = children.filter(child => !(child instanceof Comment))
|
|
|
+ if (children.length === 1) {
|
|
|
+ registerDynamicFragmentUpdated(children[0], cacheBlock)
|
|
|
+ }
|
|
|
if (children.length > 1) {
|
|
|
if (__DEV__) {
|
|
|
warn(`KeepAlive should contain exactly one component child.`)
|
|
|
@@ -402,6 +406,20 @@ const VaporKeepAliveImpl = defineVaporComponent({
|
|
|
export const VaporKeepAlive: DefineVaporComponent<{}, string, KeepAliveProps> =
|
|
|
/*@__PURE__*/ withKeepAliveEnabled(VaporKeepAliveImpl)
|
|
|
|
|
|
+function registerDynamicFragmentUpdated(
|
|
|
+ block: Block,
|
|
|
+ cacheBlock: (block?: Block) => void,
|
|
|
+): void {
|
|
|
+ if (!isDynamicFragment(block)) return
|
|
|
+ ;(block.onUpdated ||= []).unshift(() => {
|
|
|
+ if (block.$transition && block.$transition.mode === 'out-in') {
|
|
|
+ // For out-in transition, call cacheBlock after renderBranch completes
|
|
|
+ // because KeepAlive's onUpdated fires before the deferred rendering finishes.
|
|
|
+ cacheBlock(block)
|
|
|
+ }
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
const shouldCache = (
|
|
|
block: GenericComponentInstance | VaporFragment,
|
|
|
props: KeepAliveProps,
|