Home / Function/ createResult() — astro Function Reference

createResult() — astro Function Reference

Architecture documentation for the createResult() function in render-context.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  a5aa2ebd_017c_5d62_5d0a_febacd4846ac["createResult()"]
  b7425a46_8c1f_1122_7ae3_a00e52db1d90["RenderContext"]
  a5aa2ebd_017c_5d62_5d0a_febacd4846ac -->|defined in| b7425a46_8c1f_1122_7ae3_a00e52db1d90
  9c5f11d9_36cd_d739_b7da_42358d602de6["render()"]
  9c5f11d9_36cd_d739_b7da_42358d602de6 -->|calls| a5aa2ebd_017c_5d62_5d0a_febacd4846ac
  92ee7d0b_4309_452e_10ee_49559c26b54e["createAstro()"]
  a5aa2ebd_017c_5d62_5d0a_febacd4846ac -->|calls| 92ee7d0b_4309_452e_10ee_49559c26b54e
  9c5f11d9_36cd_d739_b7da_42358d602de6["render()"]
  a5aa2ebd_017c_5d62_5d0a_febacd4846ac -->|calls| 9c5f11d9_36cd_d739_b7da_42358d602de6
  style a5aa2ebd_017c_5d62_5d0a_febacd4846ac fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/astro/src/core/render-context.ts lines 518–612

	async createResult(mod: ComponentInstance, ctx: ActionAPIContext): Promise<SSRResult> {
		const { cookies, pathname, pipeline, routeData, status } = this;
		const { clientDirectives, inlinedScripts, compressHTML, manifest, renderers, resolve } =
			pipeline;
		const { links, scripts, styles } = await pipeline.headElements(routeData);

		const extraStyleHashes = [];
		const extraScriptHashes = [];
		const shouldInjectCspMetaTags = this.shouldInjectCspMetaTags;
		const cspAlgorithm = manifest.csp?.algorithm ?? 'SHA-256';
		if (shouldInjectCspMetaTags) {
			for (const style of styles) {
				extraStyleHashes.push(await generateCspDigest(style.children, cspAlgorithm));
			}

			for (const script of scripts) {
				extraScriptHashes.push(await generateCspDigest(script.children, cspAlgorithm));
			}
		}

		const componentMetadata =
			(await pipeline.componentMetadata(routeData)) ?? manifest.componentMetadata;
		const headers = new Headers({ 'Content-Type': 'text/html' });
		const partial = typeof this.partial === 'boolean' ? this.partial : Boolean(mod.partial);
		const actionResult = hasActionPayload(this.locals)
			? deserializeActionResult(this.locals._actionPayload.actionResult)
			: undefined;
		const response = {
			status: actionResult?.error ? actionResult?.error.status : status,
			statusText: actionResult?.error ? actionResult?.error.type : 'OK',
			get headers() {
				return headers;
			},
			// Disallow `Astro.response.headers = new Headers`
			set headers(_) {
				throw new AstroError(AstroErrorData.AstroResponseHeadersReassigned);
			},
		} satisfies AstroGlobal['response'];

		// Create the result object that will be passed into the renderPage function.
		// This object starts here as an empty shell (not yet the result) but then
		// calling the render() function will populate the object with scripts, styles, etc.
		const result: SSRResult = {
			base: manifest.base,
			userAssetsBase: manifest.userAssetsBase,
			cancelled: false,
			clientDirectives,
			inlinedScripts,
			componentMetadata,
			compressHTML,
			cookies,
			/** This function returns the `Astro` faux-global */
			createAstro: (props, slots) => this.createAstro(result, props, slots, ctx),
			links,
			params: this.params,
			partial,
			pathname,
			renderers,
			resolve,
			response,
			request: this.request,
			scripts,
			styles,
			actionResult,
			serverIslandNameMap: this.serverIslands.serverIslandNameMap ?? new Map(),
			key: manifest.key,
			trailingSlash: manifest.trailingSlash,
			_metadata: {
				hasHydrationScript: false,
				rendererSpecificHydrationScripts: new Set(),
				hasRenderedHead: false,
				renderedScripts: new Set(),
				hasDirectives: new Set(),
				hasRenderedServerIslandRuntime: false,
				headInTree: false,
				extraHead: [],
				extraStyleHashes,
				extraScriptHashes,
				propagators: new Set(),
			},
			cspDestination: manifest.csp?.cspDestination ?? (routeData.prerender ? 'meta' : 'header'),

Domain

Subdomains

Called By

Frequently Asked Questions

What does createResult() do?
createResult() is a function in the astro codebase, defined in packages/astro/src/core/render-context.ts.
Where is createResult() defined?
createResult() is defined in packages/astro/src/core/render-context.ts at line 518.
What does createResult() call?
createResult() calls 2 function(s): createAstro, render.
What calls createResult()?
createResult() is called by 1 function(s): render.

Analyze Your Own Codebase

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

Try Supermodel Free