feat: update Suspense usage (#2099)

See https://github.com/vuejs/vue-next/pull/2099 for details.
This commit is contained in:
Evan You
2020-09-15 12:45:06 -04:00
committed by GitHub
parent 37e686f25e
commit 5ae7380b4a
17 changed files with 815 additions and 247 deletions

View File

@@ -25,7 +25,8 @@ import { AppContext } from './apiCreateApp'
import {
SuspenseImpl,
isSuspense,
SuspenseBoundary
SuspenseBoundary,
normalizeSuspenseChildren
} from './components/Suspense'
import { DirectiveBinding } from './directives'
import { TransitionHooks } from './components/BaseTransition'
@@ -134,7 +135,6 @@ export interface VNode<
scopeId: string | null // SFC only
children: VNodeNormalizedChildren
component: ComponentInternalInstance | null
suspense: SuspenseBoundary | null
dirs: DirectiveBinding[] | null
transition: TransitionHooks<HostElement> | null
@@ -145,6 +145,11 @@ export interface VNode<
targetAnchor: HostNode | null // teleport target anchor
staticCount: number // number of elements contained in a static vnode
// suspense
suspense: SuspenseBoundary | null
ssContent: VNode | null
ssFallback: VNode | null
// optimization only
shapeFlag: number
patchFlag: number
@@ -395,6 +400,8 @@ function _createVNode(
children: null,
component: null,
suspense: null,
ssContent: null,
ssFallback: null,
dirs: null,
transition: null,
el: null,
@@ -416,6 +423,13 @@ function _createVNode(
normalizeChildren(vnode, children)
// normalize suspense children
if (__FEATURE_SUSPENSE__ && shapeFlag & ShapeFlags.SUSPENSE) {
const { content, fallback } = normalizeSuspenseChildren(vnode)
vnode.ssContent = content
vnode.ssFallback = fallback
}
if (
shouldTrack > 0 &&
// avoid a block node from tracking itself
@@ -491,6 +505,8 @@ export function cloneVNode<T, U>(
// they will simply be overwritten.
component: vnode.component,
suspense: vnode.suspense,
ssContent: vnode.ssContent && cloneVNode(vnode.ssContent),
ssFallback: vnode.ssFallback && cloneVNode(vnode.ssFallback),
el: vnode.el,
anchor: vnode.anchor
}