vue3-yuanma/packages/server-renderer/src/helpers/ssrRenderPortal.ts

21 lines
572 B
TypeScript
Raw Normal View History

import { ComponentInternalInstance, ssrContextKey } from 'vue'
import { SSRContext, createBuffer, PushFn } from '../renderToString'
export function ssrRenderPortal(
contentRenderFn: (push: PushFn) => void,
target: string,
parentComponent: ComponentInternalInstance
) {
const { getBuffer, push } = createBuffer()
contentRenderFn(push)
const context = parentComponent.appContext.provides[
ssrContextKey as any
] as SSRContext
const portalBuffers =
context.__portalBuffers || (context.__portalBuffers = {})
portalBuffers[target] = getBuffer()
}