feat(portal): SSR support for multi portal shared target
This commit is contained in:
@@ -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()]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user