diff --git a/packages/astro/src/core/build/generate.ts b/packages/astro/src/core/build/generate.ts index 0c1e077aa61b..9a1bf647dfb1 100644 --- a/packages/astro/src/core/build/generate.ts +++ b/packages/astro/src/core/build/generate.ts @@ -506,11 +506,23 @@ async function generatePath( onRequest as MiddlewareResponseHandler, apiContext, () => { - return renderPage({ mod, renderContext, env, apiContext, isCompressHTML: settings.config.compressHTML }); + return renderPage({ + mod, + renderContext, + env, + apiContext, + isCompressHTML: settings.config.compressHTML, + }); } ); } else { - response = await renderPage({ mod, renderContext, env, apiContext, isCompressHTML: settings.config.compressHTML }); + response = await renderPage({ + mod, + renderContext, + env, + apiContext, + isCompressHTML: settings.config.compressHTML, + }); } } catch (err) { if (!AstroError.is(err) && !(err as SSRError).id && typeof err === 'object') { diff --git a/packages/astro/src/core/render/core.ts b/packages/astro/src/core/render/core.ts index 4ca8225830ba..1973a84c3916 100644 --- a/packages/astro/src/core/render/core.ts +++ b/packages/astro/src/core/render/core.ts @@ -108,10 +108,16 @@ export type RenderPage = { renderContext: RenderContext; env: Environment; apiContext?: APIContext; - isCompressHTML?: boolean + isCompressHTML?: boolean; }; -export async function renderPage({ mod, renderContext, env, apiContext, isCompressHTML = false }: RenderPage) { +export async function renderPage({ + mod, + renderContext, + env, + apiContext, + isCompressHTML = false, +}: RenderPage) { // Validate the page component before rendering the page const Component = mod.default; if (!Component) diff --git a/packages/astro/src/runtime/server/render/page.ts b/packages/astro/src/runtime/server/render/page.ts index 5bbca039f340..d7b81e96c2e1 100644 --- a/packages/astro/src/runtime/server/render/page.ts +++ b/packages/astro/src/runtime/server/render/page.ts @@ -40,7 +40,7 @@ async function iterableToHTMLBytes( if (i === 0) { i++; if (!/' : '\n'}`, result); + parts.append(`${isCompressHTML ? '' : '\n'}`, result); if (onDocTypeInjection) { await onDocTypeInjection(parts); } @@ -154,7 +154,11 @@ export async function renderPage( if (isHTMLString(chunk)) { if (i === 0) { if (!/' : '\n'}`)); + controller.enqueue( + encoder.encode( + `${isCompressHTML ? '' : '\n'}` + ) + ); } } }