render() — astro Function Reference
Architecture documentation for the render() function in render-context.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD 9c5f11d9_36cd_d739_b7da_42358d602de6["render()"] b7425a46_8c1f_1122_7ae3_a00e52db1d90["RenderContext"] 9c5f11d9_36cd_d739_b7da_42358d602de6 -->|defined in| b7425a46_8c1f_1122_7ae3_a00e52db1d90 7f259d51_047e_dff1_1c2a_d2b734d46b09["reroutePayload()"] 7f259d51_047e_dff1_1c2a_d2b734d46b09 -->|calls| 9c5f11d9_36cd_d739_b7da_42358d602de6 a5aa2ebd_017c_5d62_5d0a_febacd4846ac["createResult()"] a5aa2ebd_017c_5d62_5d0a_febacd4846ac -->|calls| 9c5f11d9_36cd_d739_b7da_42358d602de6 d91ba7de_e6ec_e3f2_d698_49f283edc9ab["createActionAPIContext()"] 9c5f11d9_36cd_d739_b7da_42358d602de6 -->|calls| d91ba7de_e6ec_e3f2_d698_49f283edc9ab 0acd3c04_45a9_5c6b_ac3e_c0da8b6644c2["createAPIContext()"] 9c5f11d9_36cd_d739_b7da_42358d602de6 -->|calls| 0acd3c04_45a9_5c6b_ac3e_c0da8b6644c2 a5aa2ebd_017c_5d62_5d0a_febacd4846ac["createResult()"] 9c5f11d9_36cd_d739_b7da_42358d602de6 -->|calls| a5aa2ebd_017c_5d62_5d0a_febacd4846ac style 9c5f11d9_36cd_d739_b7da_42358d602de6 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/astro/src/core/render-context.ts lines 183–349
async render(
componentInstance: ComponentInstance | undefined,
slots: Record<string, any> = {},
): Promise<Response> {
const { middleware, pipeline } = this;
const { logger, streaming, manifest } = pipeline;
const props =
Object.keys(this.props).length > 0
? this.props
: await getProps({
mod: componentInstance,
routeData: this.routeData,
routeCache: this.pipeline.routeCache,
pathname: this.pathname,
logger,
serverLike: manifest.serverLike,
base: manifest.base,
trailingSlash: manifest.trailingSlash,
});
const actionApiContext = this.createActionAPIContext();
const apiContext = this.createAPIContext(props, actionApiContext);
this.counter++;
if (this.counter === 4) {
return new Response('Loop Detected', {
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/508
status: 508,
statusText:
'Astro detected a loop where you tried to call the rewriting logic more than four times.',
});
}
const lastNext = async (ctx: APIContext, payload?: RewritePayload) => {
if (payload) {
const oldPathname = this.pathname;
pipeline.logger.debug('router', 'Called rewriting to:', payload);
// we intentionally let the error bubble up
const {
routeData,
componentInstance: newComponent,
pathname,
newUrl,
} = await pipeline.tryRewrite(payload, this.request);
// This is a case where the user tries to rewrite from a SSR route to a prerendered route (SSG).
// This case isn't valid because when building for SSR, the prerendered route disappears from the server output because it becomes an HTML file,
// so Astro can't retrieve it from the emitted manifest.
if (
this.pipeline.manifest.serverLike === true &&
this.routeData.prerender === false &&
routeData.prerender === true
) {
throw new AstroError({
...ForbiddenRewrite,
message: ForbiddenRewrite.message(this.pathname, pathname, routeData.component),
hint: ForbiddenRewrite.hint(routeData.component),
});
}
this.routeData = routeData;
componentInstance = newComponent;
if (payload instanceof Request) {
this.request = payload;
} else {
this.request = copyRequest(
newUrl,
this.request,
// need to send the flag of the previous routeData
routeData.prerender,
this.pipeline.logger,
this.routeData.route,
);
}
this.isRewriting = true;
this.url = RenderContext.#createNormalizedUrl(this.request.url);
this.params = getParams(routeData, pathname);
this.pathname = pathname;
this.status = 200;
setOriginPathname(
this.request,
oldPathname,
this.pipeline.manifest.trailingSlash,
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does render() do?
render() is a function in the astro codebase, defined in packages/astro/src/core/render-context.ts.
Where is render() defined?
render() is defined in packages/astro/src/core/render-context.ts at line 183.
What does render() call?
render() calls 3 function(s): createAPIContext, createActionAPIContext, createResult.
What calls render()?
render() is called by 2 function(s): createResult, reroutePayload.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free