wip(ssr): renderer support for optimized and manual slots

This commit is contained in:
Evan You
2020-01-28 22:58:02 -05:00
parent a7b0954f14
commit 6b1ce00621
9 changed files with 86 additions and 37 deletions

View File

@@ -12,7 +12,7 @@ import {
TestElement,
TestNode
} from '@vue/runtime-test'
import { VNodeChildren } from '../src/vnode'
import { VNodeArrayChildren } from '../src/vnode'
describe('renderer: portal', () => {
test('should work', () => {
@@ -60,7 +60,7 @@ describe('renderer: portal', () => {
test('should update children', async () => {
const target = nodeOps.createElement('div')
const root = nodeOps.createElement('div')
const children = ref<VNodeChildren<TestNode, TestElement>>([
const children = ref<VNodeArrayChildren<TestNode, TestElement>>([
h('div', 'teleported')
])

View File

@@ -1,5 +1,10 @@
import { ComponentInternalInstance, currentInstance } from './component'
import { VNode, NormalizedChildren, normalizeVNode, VNodeChild } from './vnode'
import {
VNode,
VNodeNormalizedChildren,
normalizeVNode,
VNodeChild
} from './vnode'
import { isArray, isFunction, EMPTY_OBJ } from '@vue/shared'
import { ShapeFlags } from './shapeFlags'
import { warn } from './warning'
@@ -41,7 +46,7 @@ const normalizeSlot = (key: string, rawSlot: Function): Slot => (
export function resolveSlots(
instance: ComponentInternalInstance,
children: NormalizedChildren
children: VNodeNormalizedChildren
) {
let slots: InternalSlots | void
if (instance.vnode.shapeFlag & ShapeFlags.SLOTS_CHILDREN) {

View File

@@ -9,7 +9,7 @@ import {
Comment,
isSameVNodeType,
VNode,
VNodeChildren
VNodeArrayChildren
} from '../vnode'
import { warn } from '../warning'
import { isKeepAlive } from './KeepAlive'
@@ -370,7 +370,7 @@ function emptyPlaceholder(vnode: VNode): VNode | undefined {
function getKeepAliveChild(vnode: VNode): VNode | undefined {
return isKeepAlive(vnode)
? vnode.children
? ((vnode.children as VNodeChildren)[0] as VNode)
? ((vnode.children as VNodeArrayChildren)[0] as VNode)
: undefined
: vnode
}

View File

@@ -2,7 +2,7 @@ import {
VNode,
VNodeProps,
createVNode,
VNodeChildren,
VNodeArrayChildren,
Fragment,
Portal,
isVNode
@@ -62,7 +62,7 @@ type RawChildren =
| number
| boolean
| VNode
| VNodeChildren
| VNodeArrayChildren
| (() => any)
// fake constructor type returned from `defineComponent`
@@ -85,11 +85,11 @@ export function h(
): VNode
// fragment
export function h(type: typeof Fragment, children?: VNodeChildren): VNode
export function h(type: typeof Fragment, children?: VNodeArrayChildren): VNode
export function h(
type: typeof Fragment,
props?: RawProps | null,
children?: VNodeChildren
children?: VNodeArrayChildren
): VNode
// portal (target prop is required)

View File

@@ -1,7 +1,7 @@
import { Data } from '../component'
import { Slot } from '../componentSlots'
import {
VNodeChildren,
VNodeArrayChildren,
openBlock,
createBlock,
Fragment,
@@ -15,7 +15,7 @@ export function renderSlot(
props: Data = {},
// this is not a user-facing function, so the fallback is always generated by
// the compiler and guaranteed to be an array
fallback?: VNodeChildren
fallback?: VNodeArrayChildren
): VNode {
const slot = slots[name]
return (

View File

@@ -125,7 +125,13 @@ export {
Plugin,
CreateAppFunction
} from './apiCreateApp'
export { VNode, VNodeTypes, VNodeProps, VNodeChildren } from './vnode'
export {
VNode,
VNodeTypes,
VNodeProps,
VNodeArrayChildren,
VNodeNormalizedChildren
} from './vnode'
export {
Component,
FunctionalComponent,

View File

@@ -6,7 +6,7 @@ import {
cloneIfMounted,
normalizeVNode,
VNode,
VNodeChildren,
VNodeArrayChildren,
createVNode,
isSameVNodeType
} from './vnode'
@@ -177,7 +177,7 @@ export function createRenderer<
createApp: CreateAppFunction<HostElement>
} {
type HostVNode = VNode<HostNode, HostElement>
type HostVNodeChildren = VNodeChildren<HostNode, HostElement>
type HostVNodeChildren = VNodeArrayChildren<HostNode, HostElement>
type HostSuspenseBoundary = SuspenseBoundary<HostNode, HostElement>
const {

View File

@@ -71,19 +71,19 @@ type VNodeChildAtom<HostNode, HostElement> =
| null
| void
export interface VNodeChildren<HostNode = any, HostElement = any>
export interface VNodeArrayChildren<HostNode = any, HostElement = any>
extends Array<
| VNodeChildren<HostNode, HostElement>
| VNodeArrayChildren<HostNode, HostElement>
| VNodeChildAtom<HostNode, HostElement>
> {}
export type VNodeChild<HostNode = any, HostElement = any> =
| VNodeChildAtom<HostNode, HostElement>
| VNodeChildren<HostNode, HostElement>
| VNodeArrayChildren<HostNode, HostElement>
export type NormalizedChildren<HostNode = any, HostElement = any> =
export type VNodeNormalizedChildren<HostNode = any, HostElement = any> =
| string
| VNodeChildren<HostNode, HostElement>
| VNodeArrayChildren<HostNode, HostElement>
| RawSlots
| null
@@ -94,7 +94,7 @@ export interface VNode<HostNode = any, HostElement = any> {
key: string | number | null
ref: string | Ref | ((ref: object | null) => void) | null
scopeId: string | null // SFC only
children: NormalizedChildren<HostNode, HostElement>
children: VNodeNormalizedChildren<HostNode, HostElement>
component: ComponentInternalInstance | null
suspense: SuspenseBoundary<HostNode, HostElement> | null
dirs: DirectiveBinding[] | null
@@ -376,7 +376,7 @@ export function normalizeChildren(vnode: VNode, children: unknown) {
children = String(children)
type = ShapeFlags.TEXT_CHILDREN
}
vnode.children = children as NormalizedChildren
vnode.children = children as VNodeNormalizedChildren
vnode.shapeFlag |= type
}