Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable streaming for SSG #10796

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/eight-hotels-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"astro": patch
---

Disables streaming when rendering site with `output: "static"`
3 changes: 2 additions & 1 deletion packages/astro/src/core/build/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions packages/astro/src/runtime/server/render/astro/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export async function renderToString(
let str = '';
let renderedFirstPageChunk = false;

if (isPage) {
await bufferHeadContent(result);
}
Comment on lines +34 to +36
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the missing piece to make the non-streaming render work. It exists in renderToReadableStream but wasn't ported here too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So simple!


const destination: RenderDestination = {
write(chunk) {
// Automatic doctype insertion for pages
Expand Down
6 changes: 1 addition & 5 deletions packages/astro/test/content-collections-render.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
Loading