Skip to content

Commit

Permalink
fix: ensure pageContext.ssrContext is always defined
Browse files Browse the repository at this point in the history
  • Loading branch information
brillout committed Aug 30, 2024
1 parent 38f594a commit 1c0b011
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions packages/vike-vue/src/integration/onRenderHtml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const onRenderHtml: OnRenderHtmlAsync = async (
export type PageHtmlStream = ReturnType<typeof renderToNodeStream> | ReturnType<typeof renderToWebStream>
async function getPageHtml(pageContext: PageContextServer) {
let pageHtml: ReturnType<typeof dangerouslySkipEscape> | PageHtmlStream | string = ''
const ssrContext: SSRContext = {}
pageContext.ssrContext = {}
const fromHtmlRenderer: PageContextServer['fromHtmlRenderer'] = {}

let app: App | undefined
Expand All @@ -74,14 +74,14 @@ async function getPageHtml(pageContext: PageContextServer) {
assert(app)

if (!pageContext.config.stream) {
const pageHtmlString = await renderToStringWithErrorHandling(app, ssrContext)
const pageHtmlString = await renderToStringWithErrorHandling(app, pageContext.ssrContext)
pageContext.pageHtmlString = pageHtmlString
pageHtml = dangerouslySkipEscape(pageHtmlString)
} else {
const pageHtmlStream =
pageContext.config.stream === 'web'
? renderToWebStreamWithErrorHandling(app, ssrContext)
: renderToNodeStreamWithErrorHandling(app, ssrContext)
? renderToWebStreamWithErrorHandling(app, pageContext.ssrContext)
: renderToNodeStreamWithErrorHandling(app, pageContext.ssrContext)
pageContext.pageHtmlStream = pageHtmlStream
pageHtml = pageHtmlStream
}
Expand All @@ -91,7 +91,6 @@ async function getPageHtml(pageContext: PageContextServer) {
// - Tell users to use `!!pageContext.Page` if they want to apply the hook only for SSR.
// - Already done: https://vike.dev/onAfterRenderHtml
const afterRenderResults = await callCumulativeHooks(pageContext.config.onAfterRenderHtml, pageContext)
pageContext.ssrContext = ssrContext
Object.assign(fromHtmlRenderer, ...afterRenderResults)
}
return { pageHtml, fromHtmlRenderer }
Expand Down

0 comments on commit 1c0b011

Please sign in to comment.