Home / Function/ callComponentAsTemplateResultOrResponse() — astro Function Reference

callComponentAsTemplateResultOrResponse() — astro Function Reference

Architecture documentation for the callComponentAsTemplateResultOrResponse() function in render.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  531bf937_76da_4b29_be5c_c5f57d933834["callComponentAsTemplateResultOrResponse()"]
  e0446a2c_f6ef_c306_3fa2_3d3016b94419["render.ts"]
  531bf937_76da_4b29_be5c_c5f57d933834 -->|defined in| e0446a2c_f6ef_c306_3fa2_3d3016b94419
  4f0f8a5d_2080_3d78_cf45_50811bf15a70["renderToString()"]
  4f0f8a5d_2080_3d78_cf45_50811bf15a70 -->|calls| 531bf937_76da_4b29_be5c_c5f57d933834
  a1e1182e_4683_0c1e_4777_d9c6023779e8["renderToReadableStream()"]
  a1e1182e_4683_0c1e_4777_d9c6023779e8 -->|calls| 531bf937_76da_4b29_be5c_c5f57d933834
  a4540b08_b256_31dc_609c_62af4c628a44["renderToAsyncIterable()"]
  a4540b08_b256_31dc_609c_62af4c628a44 -->|calls| 531bf937_76da_4b29_be5c_c5f57d933834
  style 531bf937_76da_4b29_be5c_c5f57d933834 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/astro/src/runtime/server/render/astro/render.ts lines 147–188

async function callComponentAsTemplateResultOrResponse(
	result: SSRResult,
	componentFactory: AstroComponentFactory,
	props: any,
	children: any,
	route?: RouteData,
) {
	const factoryResult = await componentFactory(result, props, children);

	if (factoryResult instanceof Response) {
		return factoryResult;
	}
	// we check if the component we attempt to render is a head+content
	else if (isHeadAndContent(factoryResult)) {
		// we make sure that content is valid template result
		if (!isRenderTemplateResult(factoryResult.content)) {
			throw new AstroError({
				...AstroErrorData.OnlyResponseCanBeReturned,
				message: AstroErrorData.OnlyResponseCanBeReturned.message(
					route?.route,
					typeof factoryResult,
				),
				location: {
					file: route?.component,
				},
			});
		}

		// return the content
		return factoryResult.content;
	} else if (!isRenderTemplateResult(factoryResult)) {
		throw new AstroError({
			...AstroErrorData.OnlyResponseCanBeReturned,
			message: AstroErrorData.OnlyResponseCanBeReturned.message(route?.route, typeof factoryResult),
			location: {
				file: route?.component,
			},
		});
	}

	return factoryResult;
}

Domain

Subdomains

Frequently Asked Questions

What does callComponentAsTemplateResultOrResponse() do?
callComponentAsTemplateResultOrResponse() is a function in the astro codebase, defined in packages/astro/src/runtime/server/render/astro/render.ts.
Where is callComponentAsTemplateResultOrResponse() defined?
callComponentAsTemplateResultOrResponse() is defined in packages/astro/src/runtime/server/render/astro/render.ts at line 147.
What calls callComponentAsTemplateResultOrResponse()?
callComponentAsTemplateResultOrResponse() is called by 3 function(s): renderToAsyncIterable, renderToReadableStream, renderToString.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free