diff --git a/vike/node/runtime/renderPage/createHttpResponse.ts b/vike/node/runtime/renderPage/createHttpResponse.ts index 7392b04d7c5..cc809e14c57 100644 --- a/vike/node/runtime/renderPage/createHttpResponse.ts +++ b/vike/node/runtime/renderPage/createHttpResponse.ts @@ -31,7 +31,7 @@ type ContentType = HttpResponse['contentType'] type ResponseHeaders = HttpResponse['headers'] async function createHttpResponse( - htmlRender: null | HtmlRender, + htmlRender: HtmlRender, renderHook: null | RenderHook, pageContext: { _pageId: null | string @@ -41,11 +41,7 @@ async function createHttpResponse( _pageConfigs: PageConfigRuntime[] abortStatusCode?: AbortStatusCode } -): Promise { - if (htmlRender === null) { - return null - } - +): Promise { let statusCode: StatusCode | undefined = pageContext.abortStatusCode if (!statusCode) { const isError = !pageContext._pageId || isErrorPage(pageContext._pageId, pageContext._pageConfigs) diff --git a/vike/node/runtime/renderPage/executeOnRenderHtmlHook.ts b/vike/node/runtime/renderPage/executeOnRenderHtmlHook.ts index c20c6c75e2b..fdc24c86cd6 100644 --- a/vike/node/runtime/renderPage/executeOnRenderHtmlHook.ts +++ b/vike/node/runtime/renderPage/executeOnRenderHtmlHook.ts @@ -47,7 +47,7 @@ async function executeOnRenderHtmlHook( } ): Promise<{ renderHook: RenderHook - htmlRender: null | HtmlRender + htmlRender: HtmlRender }> { const { renderHook, hookFn } = getRenderHook(pageContext) objectAssign(pageContext, { _renderHook: renderHook }) @@ -62,10 +62,6 @@ async function executeOnRenderHtmlHook( Object.assign(pageContext, pageContextProvidedByRenderHook) objectAssign(pageContext, { _pageContextPromise: pageContextPromise }) - if (documentHtml === null || documentHtml === undefined) { - return { htmlRender: null, renderHook } - } - const onErrorWhileStreaming = (err: unknown) => { // Should the stream inject the following? // ``` @@ -131,7 +127,7 @@ function getRenderHook(pageContext: PageContextForUserConsumptionServerSide) { } function processHookReturnValue(hookReturnValue: unknown, renderHook: RenderHook) { - let documentHtml: null | DocumentHtml = null + let documentHtml: DocumentHtml let pageContextPromise: PageContextPromise = null let pageContextProvidedByRenderHook: null | Record = null let injectFilter: PreloadFilter = null @@ -179,7 +175,11 @@ function processHookReturnValue(hookReturnValue: unknown, renderHook: RenderHook injectFilter = hookReturnValue.injectFilter } - if (hookReturnValue.documentHtml) { + assertUsage( + hookReturnValue.documentHtml, + `${errPrefix} returned an object that is missing the ${pc.code('documentHtml')} property.` + ) + { let val = hookReturnValue.documentHtml const errBegin = `${errPrefix} returned ${pc.cyan('{ documentHtml }')}, but ${pc.cyan('documentHtml')}` as const if (typeof val === 'string') { diff --git a/vike/node/runtime/renderPage/renderPageAlreadyRouted.ts b/vike/node/runtime/renderPage/renderPageAlreadyRouted.ts index c46e47a29cc..0ffd3975a8a 100644 --- a/vike/node/runtime/renderPage/renderPageAlreadyRouted.ts +++ b/vike/node/runtime/renderPage/renderPageAlreadyRouted.ts @@ -85,15 +85,10 @@ async function renderPageAlreadyRouted< const renderHookResult = await executeOnRenderHtmlHook(pageContext) - if (renderHookResult.htmlRender === null) { - objectAssign(pageContext, { httpResponse: null }) - return pageContext - } else { - const { htmlRender, renderHook } = renderHookResult - const httpResponse = await createHttpResponse(htmlRender, renderHook, pageContext) - objectAssign(pageContext, { httpResponse }) - return pageContext - } + const { htmlRender, renderHook } = renderHookResult + const httpResponse = await createHttpResponse(htmlRender, renderHook, pageContext) + objectAssign(pageContext, { httpResponse }) + return pageContext } async function prerenderPage(