2020-03-10 20:52:08 +00:00
|
|
|
import { PushFn, ResolvedSSRBuffer, createBuffer } from '../renderToString'
|
|
|
|
|
|
|
|
type ContentRenderFn = (push: PushFn) => void
|
|
|
|
|
|
|
|
export async function ssrRenderSuspense({
|
2020-03-13 02:19:41 +00:00
|
|
|
default: renderContent,
|
|
|
|
fallback: renderFallback
|
2020-03-10 20:52:08 +00:00
|
|
|
}: Record<string, ContentRenderFn | undefined>): Promise<ResolvedSSRBuffer> {
|
|
|
|
try {
|
2020-03-13 02:19:41 +00:00
|
|
|
if (renderContent) {
|
|
|
|
const { push, getBuffer } = createBuffer()
|
2020-03-13 15:55:04 +00:00
|
|
|
push(`<!--[-->`)
|
2020-03-13 02:19:41 +00:00
|
|
|
renderContent(push)
|
2020-03-13 15:55:04 +00:00
|
|
|
push(`<!--]-->`)
|
2020-03-13 02:19:41 +00:00
|
|
|
return await getBuffer()
|
|
|
|
} else {
|
|
|
|
return []
|
|
|
|
}
|
2020-03-10 20:52:08 +00:00
|
|
|
} catch {
|
2020-03-13 02:19:41 +00:00
|
|
|
if (renderFallback) {
|
|
|
|
const { push, getBuffer } = createBuffer()
|
2020-03-13 15:55:04 +00:00
|
|
|
push(`<!--[-->`)
|
2020-03-13 02:19:41 +00:00
|
|
|
renderFallback(push)
|
2020-03-13 15:55:04 +00:00
|
|
|
push(`<!--]-->`)
|
2020-03-13 02:19:41 +00:00
|
|
|
return getBuffer()
|
|
|
|
} else {
|
|
|
|
return []
|
|
|
|
}
|
2020-03-10 20:52:08 +00:00
|
|
|
}
|
|
|
|
}
|