feat(portal): SSR support for multi portal shared target

This commit is contained in:
Evan You
2020-03-27 20:49:01 -04:00
parent aafb880a0a
commit e866434f0c
7 changed files with 130 additions and 32 deletions

View File

@@ -2,19 +2,24 @@ import { ComponentInternalInstance, ssrContextKey } from 'vue'
import { SSRContext, createBuffer, PushFn } from '../renderToString'
export function ssrRenderPortal(
parentPush: PushFn,
contentRenderFn: (push: PushFn) => void,
target: string,
parentComponent: ComponentInternalInstance
) {
parentPush('<!--portal-->')
const { getBuffer, push } = createBuffer()
contentRenderFn(push)
push(`<!---->`) // portal end anchor
const context = parentComponent.appContext.provides[
ssrContextKey as any
] as SSRContext
const portalBuffers =
context.__portalBuffers || (context.__portalBuffers = {})
portalBuffers[target] = getBuffer()
if (portalBuffers[target]) {
portalBuffers[target].push(getBuffer())
} else {
portalBuffers[target] = [getBuffer()]
}
}