Skip to content

Commit 3a2cd69

Browse files
authored
refactor(keep-alive): refactor KeepAlive to use new fragment hooks. (#14121)
1 parent 584f25f commit 3a2cd69

File tree

6 files changed

+221
-200
lines changed

6 files changed

+221
-200
lines changed

packages/runtime-core/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,3 +669,8 @@ export {
669669
checkTransitionMode,
670670
leaveCbKey,
671671
} from './components/BaseTransition'
672+
673+
/**
674+
* @internal
675+
*/
676+
export type { GenericComponent } from './component'

packages/runtime-vapor/__tests__/apiDefineAsyncComponent.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
defineVaporComponent,
1010
renderEffect,
1111
template,
12+
withVaporCtx,
1213
} from '@vue/runtime-vapor'
1314
import { setElementText } from '../src/dom/prop'
1415

@@ -785,12 +786,13 @@ describe('api: defineAsyncComponent', () => {
785786
const { html } = define({
786787
setup() {
787788
return createComponent(VaporKeepAlive, null, {
788-
default: () =>
789+
default: withVaporCtx(() =>
789790
createIf(
790791
() => toggle.value,
791792
() => createComponent(Foo),
792793
() => createComponent(Bar),
793794
),
795+
),
794796
})
795797
},
796798
}).render()
@@ -834,7 +836,7 @@ describe('api: defineAsyncComponent', () => {
834836
VaporKeepAlive,
835837
{ include: () => 'Foo' },
836838
{
837-
default: () => createComponent(Foo),
839+
default: withVaporCtx(() => createComponent(Foo)),
838840
},
839841
)
840842
},

packages/runtime-vapor/src/apiDefineAsyncComponent.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
createAsyncComponentContext,
66
currentInstance,
77
handleError,
8-
isKeepAlive,
98
markAsyncBoundary,
109
performAsyncHydrate,
1110
useAsyncComponentState,
@@ -29,7 +28,6 @@ import {
2928
import { invokeArrayFns } from '@vue/shared'
3029
import { type TransitionOptions, insert, remove } from './block'
3130
import { parentNode } from './dom/node'
32-
import type { KeepAliveInstance } from './components/KeepAlive'
3331
import { setTransitionHooks } from './components/Transition'
3432

3533
/*@ __NO_SIDE_EFFECTS__ */
@@ -193,14 +191,6 @@ function createInnerComp(
193191
appContext,
194192
)
195193

196-
if (parent.parent && isKeepAlive(parent.parent)) {
197-
// If there is a parent KeepAlive, let it handle the resolved async component
198-
// This will process shapeFlag and cache the component
199-
;(parent.parent as KeepAliveInstance).cacheComponent(instance)
200-
// cache the wrapper instance as well
201-
;(parent.parent as KeepAliveInstance).cacheComponent(parent)
202-
}
203-
204194
// set transition hooks
205195
if ($transition) setTransitionHooks(instance, $transition)
206196

packages/runtime-vapor/src/block.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,6 @@ export function remove(block: Block, parent?: ParentNode): void {
160160
if (block.anchor) remove(block.anchor, parent)
161161
if ((block as DynamicFragment).scope) {
162162
;(block as DynamicFragment).scope!.stop()
163-
const scopes = (block as DynamicFragment).keptAliveScopes
164-
if (scopes) {
165-
scopes.forEach(scope => scope.stop())
166-
scopes.clear()
167-
}
168163
}
169164
}
170165
}

0 commit comments

Comments
 (0)