mirror of
https://github.com/withastro/astro.git
synced 2025-03-10 23:01:26 -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`.
|
// we can ensure getting a value for `head`.
|
||||||
let head = '';
|
let head = '';
|
||||||
if (isPage && !result.partial && nonAstroPageNeedsHeadInjection(Component)) {
|
if (isPage && !result.partial && nonAstroPageNeedsHeadInjection(Component)) {
|
||||||
for (const headChunk of maybeRenderHead()) {
|
head += chunkToString(result, maybeRenderHead());
|
||||||
head += chunkToString(result, headChunk);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -51,16 +51,16 @@ export function renderAllHeadContent(result: SSRResult) {
|
||||||
return markHTMLString(content);
|
return markHTMLString(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function* renderHead(): Generator<RenderHeadInstruction> {
|
export function renderHead(): RenderHeadInstruction {
|
||||||
yield createRenderInstruction({ type: 'head' });
|
return createRenderInstruction({ type: 'head' });
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function is called by Astro components that do not contain a <head> component
|
// 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
|
// 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
|
// is called before a component's first non-head HTML element. If the head was
|
||||||
// already injected it is a noop.
|
// 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 is an instruction informing the page rendering that head might need rendering.
|
||||||
// This allows the page to deduplicate head injections.
|
// 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);
|
let chunk = decoder.decode(bytes);
|
||||||
chunks.push(chunk);
|
chunks.push(chunk);
|
||||||
}
|
}
|
||||||
assert.equal(chunks.length, 3);
|
assert.ok(chunks.length >= 2);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue