Skip to content

Commit

Permalink
Avoid generators in render head API (#10528)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy authored Mar 22, 2024
1 parent ca5455a commit 8cac744
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
4 changes: 1 addition & 3 deletions packages/astro/src/runtime/server/render/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,9 +516,7 @@ export async function renderComponentToString(
// we can ensure getting a value for `head`.
let head = '';
if (isPage && !result.partial && nonAstroPageNeedsHeadInjection(Component)) {
for (const headChunk of maybeRenderHead()) {
head += chunkToString(result, headChunk);
}
head += chunkToString(result, maybeRenderHead());
}

try {
Expand Down
8 changes: 4 additions & 4 deletions packages/astro/src/runtime/server/render/head.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ export function renderAllHeadContent(result: SSRResult) {
return markHTMLString(content);
}

export function* renderHead(): Generator<RenderHeadInstruction> {
yield createRenderInstruction({ type: 'head' });
export function renderHead(): RenderHeadInstruction {
return createRenderInstruction({ type: 'head' });
}

// This function is called by Astro components that do not contain a <head> component
// This accommodates the fact that using a <head> is optional in Astro, so this
// is called before a component's first non-head HTML element. If the head was
// already injected it is a noop.
export function* maybeRenderHead(): Generator<MaybeRenderHeadInstruction> {
export function maybeRenderHead(): MaybeRenderHeadInstruction {
// This is an instruction informing the page rendering that head might need rendering.
// This allows the page to deduplicate head injections.
yield createRenderInstruction({ type: 'maybe-head' });
return createRenderInstruction({ type: 'maybe-head' });
}
2 changes: 1 addition & 1 deletion packages/astro/test/streaming.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('Streaming', () => {
let chunk = decoder.decode(bytes);
chunks.push(chunk);
}
assert.equal(chunks.length, 3);
assert.ok(chunks.length >= 2);
});
});

Expand Down

0 comments on commit 8cac744

Please sign in to comment.