mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
Avoid generators in render head API (#10528)
This commit is contained in:
parent
ca5455af3d
commit
8cac744746
3 changed files with 6 additions and 8 deletions
|
@ -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 {
|
||||
|
|
|
@ -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' });
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ describe('Streaming', () => {
|
|||
let chunk = decoder.decode(bytes);
|
||||
chunks.push(chunk);
|
||||
}
|
||||
assert.equal(chunks.length, 3);
|
||||
assert.ok(chunks.length >= 2);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue