renderPage() — astro Function Reference
Architecture documentation for the renderPage() function in page.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD faa665c4_2aab_86bb_d34e_66aec03a3c98["renderPage()"] cc6ae1bd_6211_1fa2_3099_a5a8ba9a887a["page.ts"] faa665c4_2aab_86bb_d34e_66aec03a3c98 -->|defined in| cc6ae1bd_6211_1fa2_3099_a5a8ba9a887a style faa665c4_2aab_86bb_d34e_66aec03a3c98 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/astro/src/runtime/server/render/page.ts lines 10–118
export async function renderPage(
result: SSRResult,
componentFactory: AstroComponentFactory | NonAstroPageComponent,
props: any,
children: any,
streaming: boolean,
route?: RouteData,
): Promise<Response> {
if (!isAstroComponentFactory(componentFactory)) {
result._metadata.headInTree =
result.componentMetadata.get((componentFactory as any).moduleId)?.containsHead ?? false;
const pageProps: Record<string, any> = { ...(props ?? {}), 'server:root': true };
const str = await renderComponentToString(
result,
componentFactory.name,
componentFactory,
pageProps,
{},
true,
route,
);
const bytes = encoder.encode(str);
const headers = new Headers([
['Content-Type', 'text/html'],
['Content-Length', bytes.byteLength.toString()],
]);
if (
result.shouldInjectCspMetaTags &&
(result.cspDestination === 'header' || result.cspDestination === 'adapter')
) {
headers.set('content-security-policy', renderCspContent(result));
}
return new Response(bytes, {
headers,
status: result.response.status,
});
}
// Mark if this page component contains a <head> within its tree. If it does
// We avoid implicit head injection entirely.
result._metadata.headInTree =
result.componentMetadata.get(componentFactory.moduleId!)?.containsHead ?? false;
let body: BodyInit | Response;
if (streaming) {
// isNode is true in Deno node-compat mode but response construction from
// async iterables is not supported, so we fallback to ReadableStream if isDeno is true.
if (isNode && !isDeno) {
const nodeBody = await renderToAsyncIterable(
result,
componentFactory,
props,
children,
true,
route,
);
// Node.js allows passing in an AsyncIterable to the Response constructor.
// This is non-standard so using `any` here to preserve types everywhere else.
body = nodeBody as any;
} else {
body = await renderToReadableStream(result, componentFactory, props, children, true, route);
}
} else {
body = await renderToString(result, componentFactory, props, children, true, route);
}
// If the Astro component returns a Response on init, return that response
if (body instanceof Response) return body;
// Create final response from body
const init = result.response;
const headers = new Headers(init.headers);
if (
(result.shouldInjectCspMetaTags && result.cspDestination === 'header') ||
result.cspDestination === 'adapter'
) {
headers.set('content-security-policy', renderCspContent(result));
Domain
Subdomains
Source
Frequently Asked Questions
What does renderPage() do?
renderPage() is a function in the astro codebase, defined in packages/astro/src/runtime/server/render/page.ts.
Where is renderPage() defined?
renderPage() is defined in packages/astro/src/runtime/server/render/page.ts at line 10.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free