diff --git a/packages/runtime-core/src/h.ts b/packages/runtime-core/src/h.ts index eebee368..b7a9ff49 100644 --- a/packages/runtime-core/src/h.ts +++ b/packages/runtime-core/src/h.ts @@ -5,7 +5,8 @@ import { VNodeChildren, Fragment, Portal, - isVNode + isVNode, + Suspense } from './vnode' import { isObject, isArray } from '@vue/shared' import { Ref } from '@vue/reactivity' @@ -102,6 +103,19 @@ export function h( children?: RawChildren ): VNode +// suspense +export function h(type: typeof Suspense, children?: RawChildren): VNode +export function h( + type: typeof Suspense, + props?: + | (RawProps & { + onResolve?: () => void + onRecede?: () => void + }) + | null, + children?: RawChildren | RawSlots +): VNode + // functional component export function h(type: FunctionalComponent, children?: RawChildren): VNode export function h

( diff --git a/packages/runtime-core/src/suspense.ts b/packages/runtime-core/src/suspense.ts index 2a7019c7..bda5ae07 100644 --- a/packages/runtime-core/src/suspense.ts +++ b/packages/runtime-core/src/suspense.ts @@ -196,7 +196,7 @@ export interface SuspenseBoundary< isUnmounted: boolean effects: Function[] resolve(): void - restart(): void + recede(): void move(container: HostElement, anchor: HostNode | null): void next(): HostNode | null registerDep( @@ -315,7 +315,7 @@ function createSuspenseBoundary( } }, - restart() { + recede() { suspense.isResolved = false const { vnode, @@ -349,10 +349,10 @@ function createSuspenseBoundary( updateHOCHostEl(parentComponent, el) } - // invoke @suspense event - const onSuspense = vnode.props && vnode.props.onSuspense - if (isFunction(onSuspense)) { - onSuspense() + // invoke @recede event + const onRecede = vnode.props && vnode.props.onRecede + if (isFunction(onRecede)) { + onRecede() } }, @@ -377,7 +377,7 @@ function createSuspenseBoundary( // suspense tree if (suspense.isResolved) { queueJob(() => { - suspense.restart() + suspense.recede() }) } diff --git a/packages/runtime-core/src/vnode.ts b/packages/runtime-core/src/vnode.ts index cf8c4e5e..882ba059 100644 --- a/packages/runtime-core/src/vnode.ts +++ b/packages/runtime-core/src/vnode.ts @@ -25,7 +25,9 @@ export const Portal = Symbol(__DEV__ ? 'Portal' : undefined) export const Text = Symbol(__DEV__ ? 'Text' : undefined) export const Comment = Symbol(__DEV__ ? 'Comment' : undefined) -const Suspense = __FEATURE_SUSPENSE__ ? SuspenseImpl : null +const Suspense = (__FEATURE_SUSPENSE__ + ? SuspenseImpl + : null) as typeof SuspenseImpl export { Suspense } export type VNodeTypes =