renderToString() — astro Function Reference
Architecture documentation for the renderToString() function in render.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD 4f0f8a5d_2080_3d78_cf45_50811bf15a70["renderToString()"] e0446a2c_f6ef_c306_3fa2_3d3016b94419["render.ts"] 4f0f8a5d_2080_3d78_cf45_50811bf15a70 -->|defined in| e0446a2c_f6ef_c306_3fa2_3d3016b94419 531bf937_76da_4b29_be5c_c5f57d933834["callComponentAsTemplateResultOrResponse()"] 4f0f8a5d_2080_3d78_cf45_50811bf15a70 -->|calls| 531bf937_76da_4b29_be5c_c5f57d933834 a3bddb01_2167_e26f_7cb4_0806d1960ddd["bufferHeadContent()"] 4f0f8a5d_2080_3d78_cf45_50811bf15a70 -->|calls| a3bddb01_2167_e26f_7cb4_0806d1960ddd style 4f0f8a5d_2080_3d78_cf45_50811bf15a70 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/astro/src/runtime/server/render/astro/render.ts lines 19–66
export async function renderToString(
result: SSRResult,
componentFactory: AstroComponentFactory,
props: any,
children: any,
isPage = false,
route?: RouteData,
): Promise<string | Response> {
const templateResult = await callComponentAsTemplateResultOrResponse(
result,
componentFactory,
props,
children,
route,
);
// If the Astro component returns a Response on init, return that response
if (templateResult instanceof Response) return templateResult;
let str = '';
let renderedFirstPageChunk = false;
if (isPage) {
await bufferHeadContent(result);
}
const destination: RenderDestination = {
write(chunk) {
// Automatic doctype insertion for pages
if (isPage && !renderedFirstPageChunk) {
renderedFirstPageChunk = true;
if (!result.partial && !DOCTYPE_EXP.test(String(chunk))) {
const doctype = result.compressHTML ? '<!DOCTYPE html>' : '<!DOCTYPE html>\n';
str += doctype;
}
}
// `renderToString` doesn't work with emitting responses, so ignore here
if (chunk instanceof Response) return;
str += chunkToString(result, chunk);
},
};
await templateResult.render(destination);
return str;
}
Domain
Subdomains
Source
Frequently Asked Questions
What does renderToString() do?
renderToString() is a function in the astro codebase, defined in packages/astro/src/runtime/server/render/astro/render.ts.
Where is renderToString() defined?
renderToString() is defined in packages/astro/src/runtime/server/render/astro/render.ts at line 19.
What does renderToString() call?
renderToString() calls 2 function(s): bufferHeadContent, callComponentAsTemplateResultOrResponse.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free