feat: onServerPrefetch (#3070)

Support equivalent of `serverPrefetch` option via Composition API.
This commit is contained in:
Guillaume Chau
2021-05-07 18:00:52 +02:00
committed by GitHub
parent 4aceec7b5e
commit 349eb0f0ad
6 changed files with 247 additions and 21 deletions

View File

@@ -153,7 +153,7 @@ export type Component<
export { ComponentOptions }
type LifecycleHook = Function[] | null
type LifecycleHook<TFn = Function> = TFn[] | null
export const enum LifecycleHooks {
BEFORE_CREATE = 'bc',
@@ -168,7 +168,8 @@ export const enum LifecycleHooks {
ACTIVATED = 'a',
RENDER_TRIGGERED = 'rtg',
RENDER_TRACKED = 'rtc',
ERROR_CAPTURED = 'ec'
ERROR_CAPTURED = 'ec',
SERVER_PREFETCH = 'sp'
}
export interface SetupContext<E = EmitsOptions> {
@@ -414,6 +415,10 @@ export interface ComponentInternalInstance {
* @internal
*/
[LifecycleHooks.ERROR_CAPTURED]: LifecycleHook
/**
* @internal
*/
[LifecycleHooks.SERVER_PREFETCH]: LifecycleHook<() => Promise<unknown>>
}
const emptyAppContext = createAppContext()
@@ -497,7 +502,8 @@ export function createComponentInstance(
a: null,
rtg: null,
rtc: null,
ec: null
ec: null,
sp: null
}
if (__DEV__) {
instance.ctx = createRenderContext(instance)