From 26ca2fde09cf3a2ff115247485129554dfd17f40 Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Tue, 16 Apr 2024 21:21:19 +0800 Subject: [PATCH] Disable streaming for SSG (#10796) --- .changeset/eight-hotels-try.md | 5 +++++ packages/astro/src/core/build/pipeline.ts | 3 ++- packages/astro/src/runtime/server/render/astro/render.ts | 4 ++++ packages/astro/test/content-collections-render.test.js | 6 +----- 4 files changed, 12 insertions(+), 6 deletions(-) create mode 100644 .changeset/eight-hotels-try.md diff --git a/.changeset/eight-hotels-try.md b/.changeset/eight-hotels-try.md new file mode 100644 index 000000000000..f1fab2897d1f --- /dev/null +++ b/.changeset/eight-hotels-try.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +Disables streaming when rendering site with `output: "static"` diff --git a/packages/astro/src/core/build/pipeline.ts b/packages/astro/src/core/build/pipeline.ts index a89aa10f071c..245904660c18 100644 --- a/packages/astro/src/core/build/pipeline.ts +++ b/packages/astro/src/core/build/pipeline.ts @@ -53,7 +53,8 @@ export class BuildPipeline extends Pipeline { return assetLink; } const serverLike = isServerLikeOutput(config); - const streaming = true; + // We can skip streaming in SSG for performance as writing as strings are faster + const streaming = serverLike; super( options.logger, manifest, diff --git a/packages/astro/src/runtime/server/render/astro/render.ts b/packages/astro/src/runtime/server/render/astro/render.ts index 37a78725a092..f918f55c11dc 100644 --- a/packages/astro/src/runtime/server/render/astro/render.ts +++ b/packages/astro/src/runtime/server/render/astro/render.ts @@ -31,6 +31,10 @@ export async function renderToString( let str = ''; let renderedFirstPageChunk = false; + if (isPage) { + await bufferHeadContent(result); + } + const destination: RenderDestination = { write(chunk) { // Automatic doctype insertion for pages diff --git a/packages/astro/test/content-collections-render.test.js b/packages/astro/test/content-collections-render.test.js index 0e8e37fb176b..277ef8c06956 100644 --- a/packages/astro/test/content-collections-render.test.js +++ b/packages/astro/test/content-collections-render.test.js @@ -2,11 +2,7 @@ import * as assert from 'node:assert/strict'; import { after, before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import testAdapter from './test-adapter.js'; -import { isWindows, loadFixture } from './test-utils.js'; - -if (!isWindows) { - describe(); -} +import { loadFixture } from './test-utils.js'; describe('Content Collections - render()', () => { describe('Build - SSG', () => {