RenderContext Class — astro Architecture
Architecture documentation for the RenderContext class in render-context.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD b7425a46_8c1f_1122_7ae3_a00e52db1d90["RenderContext"] 26670781_0748_a2a7_7105_5e3a47a89b06["render-context.ts"] b7425a46_8c1f_1122_7ae3_a00e52db1d90 -->|defined in| 26670781_0748_a2a7_7105_5e3a47a89b06 8225581a_fdbf_53b7_3dc5_8e5da3f76d9d["constructor()"] b7425a46_8c1f_1122_7ae3_a00e52db1d90 -->|method| 8225581a_fdbf_53b7_3dc5_8e5da3f76d9d d422ab4a_ce3f_42d6_8a4b_b096a68675e5["requestUrl()"] b7425a46_8c1f_1122_7ae3_a00e52db1d90 -->|method| d422ab4a_ce3f_42d6_8a4b_b096a68675e5 0260702f_4c0c_b790_6509_b160f26390e8["create()"] b7425a46_8c1f_1122_7ae3_a00e52db1d90 -->|method| 0260702f_4c0c_b790_6509_b160f26390e8 9c5f11d9_36cd_d739_b7da_42358d602de6["render()"] b7425a46_8c1f_1122_7ae3_a00e52db1d90 -->|method| 9c5f11d9_36cd_d739_b7da_42358d602de6 0acd3c04_45a9_5c6b_ac3e_c0da8b6644c2["createAPIContext()"] b7425a46_8c1f_1122_7ae3_a00e52db1d90 -->|method| 0acd3c04_45a9_5c6b_ac3e_c0da8b6644c2 7f259d51_047e_dff1_1c2a_d2b734d46b09["reroutePayload()"] b7425a46_8c1f_1122_7ae3_a00e52db1d90 -->|method| 7f259d51_047e_dff1_1c2a_d2b734d46b09 d91ba7de_e6ec_e3f2_d698_49f283edc9ab["createActionAPIContext()"] b7425a46_8c1f_1122_7ae3_a00e52db1d90 -->|method| d91ba7de_e6ec_e3f2_d698_49f283edc9ab a5aa2ebd_017c_5d62_5d0a_febacd4846ac["createResult()"] b7425a46_8c1f_1122_7ae3_a00e52db1d90 -->|method| a5aa2ebd_017c_5d62_5d0a_febacd4846ac 92ee7d0b_4309_452e_10ee_49559c26b54e["createAstro()"] b7425a46_8c1f_1122_7ae3_a00e52db1d90 -->|method| 92ee7d0b_4309_452e_10ee_49559c26b54e 0007f436_547e_7fd2_f341_1a05d84a40a6["createAstroPagePartial()"] b7425a46_8c1f_1122_7ae3_a00e52db1d90 -->|method| 0007f436_547e_7fd2_f341_1a05d84a40a6 8738ff41_9cb5_f0e0_abb2_ec740b39d0ad["getClientAddress()"] b7425a46_8c1f_1122_7ae3_a00e52db1d90 -->|method| 8738ff41_9cb5_f0e0_abb2_ec740b39d0ad a1e64bf7_a3cd_6346_6068_fe2858acbe2e["computeCurrentLocale()"] b7425a46_8c1f_1122_7ae3_a00e52db1d90 -->|method| a1e64bf7_a3cd_6346_6068_fe2858acbe2e 259723fe_8d99_f1f3_d6ad_afa57fadf1b8["computePreferredLocale()"] b7425a46_8c1f_1122_7ae3_a00e52db1d90 -->|method| 259723fe_8d99_f1f3_d6ad_afa57fadf1b8
Relationship Graph
Source Code
packages/astro/src/core/render-context.ts lines 64–872
export class RenderContext {
private constructor(
readonly pipeline: Pipeline,
public locals: App.Locals,
readonly middleware: MiddlewareHandler,
readonly actions: SSRActions,
readonly serverIslands: ServerIslandMappings,
// It must be a DECODED pathname
public pathname: string,
public request: Request,
public routeData: RouteData,
public status: number,
public clientAddress: string | undefined,
protected cookies = new AstroCookies(request),
public params = getParams(routeData, pathname),
protected url = RenderContext.#createNormalizedUrl(request.url),
public props: Props = {},
public partial: undefined | boolean = undefined,
public shouldInjectCspMetaTags = pipeline.manifest.shouldInjectCspMetaTags,
public session: AstroSession | undefined = undefined,
public skipMiddleware = false,
) {}
static #createNormalizedUrl(requestUrl: string): URL {
const url = new URL(requestUrl);
try {
// Decode and validate pathname to prevent multi-level encoding bypass attacks
url.pathname = validateAndDecodePathname(url.pathname);
} catch {
// If validation fails, return URL with pathname as-is
// This will be caught elsewhere in the request handling pipeline
// For now, just decode without validation to maintain compatibility
try {
url.pathname = decodeURI(url.pathname);
} catch {
// If even basic decoding fails, return URL as-is
}
}
return url;
}
/**
* A flag that tells the render content if the rewriting was triggered
*/
isRewriting = false;
/**
* A safety net in case of loops
*/
counter = 0;
result: SSRResult | undefined = undefined;
static async create({
locals = {},
pathname,
pipeline,
request,
routeData,
clientAddress,
status = 200,
props,
partial = undefined,
shouldInjectCspMetaTags,
skipMiddleware = false,
}: CreateRenderContext): Promise<RenderContext> {
const pipelineMiddleware = await pipeline.getMiddleware();
const pipelineActions = await pipeline.getActions();
const pipelineSessionDriver = await pipeline.getSessionDriver();
const serverIslands = await pipeline.getServerIslands();
setOriginPathname(
request,
pathname,
pipeline.manifest.trailingSlash,
pipeline.manifest.buildFormat,
);
const cookies = new AstroCookies(request);
const session =
pipeline.manifest.sessionConfig && pipelineSessionDriver
? new AstroSession({
cookies,
config: pipeline.manifest.sessionConfig,
Domain
Defined In
Source
Frequently Asked Questions
What is the RenderContext class?
RenderContext is a class in the astro codebase, defined in packages/astro/src/core/render-context.ts.
Where is RenderContext defined?
RenderContext is defined in packages/astro/src/core/render-context.ts at line 64.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free