Home / File/ render.ts — astro Source File

render.ts — astro Source File

Architecture documentation for render.ts, a typescript file in the astro codebase. 8 imports, 0 dependents.

File typescript CoreAstro RenderingEngine 8 imports 6 functions

Entity Profile

Dependency Diagram

graph LR
  e0446a2c_f6ef_c306_3fa2_3d3016b94419["render.ts"]
  ef8a1e3f_e350_75a6_b92d_62a8566d8db9["../core/errors/index.js"]
  e0446a2c_f6ef_c306_3fa2_3d3016b94419 --> ef8a1e3f_e350_75a6_b92d_62a8566d8db9
  10d4e39f_edb6_3e34_aa93_ae1211e7da05["../types/public/internal.js"]
  e0446a2c_f6ef_c306_3fa2_3d3016b94419 --> 10d4e39f_edb6_3e34_aa93_ae1211e7da05
  a28c4b4b_41a8_d771_0fc1_f9fbc7ccded6["../util.js"]
  e0446a2c_f6ef_c306_3fa2_3d3016b94419 --> a28c4b4b_41a8_d771_0fc1_f9fbc7ccded6
  b0a43ea3_d8cf_4023_b3ca_f683a93e9dbb["./common.js"]
  e0446a2c_f6ef_c306_3fa2_3d3016b94419 --> b0a43ea3_d8cf_4023_b3ca_f683a93e9dbb
  f6f0048c_504d_27bf_f669_9d6d4a931037["./util.js"]
  e0446a2c_f6ef_c306_3fa2_3d3016b94419 --> f6f0048c_504d_27bf_f669_9d6d4a931037
  132e77ba_f68f_16dc_a64d_edda31b820dc["./astro/factory.js"]
  e0446a2c_f6ef_c306_3fa2_3d3016b94419 --> 132e77ba_f68f_16dc_a64d_edda31b820dc
  fafd37f7_4f96_f4d7_ed97_94234c7e57aa["./astro/head-and-content.js"]
  e0446a2c_f6ef_c306_3fa2_3d3016b94419 --> fafd37f7_4f96_f4d7_ed97_94234c7e57aa
  02a6e2b4_7619_f2ac_ef3f_25cd47b88fe5["./astro/render-template.js"]
  e0446a2c_f6ef_c306_3fa2_3d3016b94419 --> 02a6e2b4_7619_f2ac_ef3f_25cd47b88fe5
  style e0446a2c_f6ef_c306_3fa2_3d3016b94419 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { AstroError, AstroErrorData } from '../../../../core/errors/index.js';
import type { RouteData, SSRResult } from '../../../../types/public/internal.js';
import { isPromise } from '../../util.js';
import {
	chunkToByteArray,
	chunkToByteArrayOrString,
	chunkToString,
	encoder,
	type RenderDestination,
} from '../common.js';
import { promiseWithResolvers } from '../util.js';
import type { AstroComponentFactory } from './factory.js';
import { isHeadAndContent } from './head-and-content.js';
import { isRenderTemplateResult } from './render-template.js';

const DOCTYPE_EXP = /<!doctype html/i;

// Calls a component and renders it into a string of HTML
export async function renderToString(
	result: SSRResult,
	componentFactory: AstroComponentFactory,
	props: any,
	children: any,
	isPage = false,
	route?: RouteData,
): Promise<string | Response> {
	const templateResult = await callComponentAsTemplateResultOrResponse(
		result,
		componentFactory,
		props,
		children,
		route,
	);

	// If the Astro component returns a Response on init, return that response
	if (templateResult instanceof Response) return templateResult;

	let str = '';
	let renderedFirstPageChunk = false;

	if (isPage) {
		await bufferHeadContent(result);
	}

	const destination: RenderDestination = {
		write(chunk) {
			// Automatic doctype insertion for pages
			if (isPage && !renderedFirstPageChunk) {
				renderedFirstPageChunk = true;
				if (!result.partial && !DOCTYPE_EXP.test(String(chunk))) {
					const doctype = result.compressHTML ? '<!DOCTYPE html>' : '<!DOCTYPE html>\n';
					str += doctype;
				}
			}

			// `renderToString` doesn't work with emitting responses, so ignore here
			if (chunk instanceof Response) return;

			str += chunkToString(result, chunk);
		},
// ... (324 more lines)

Domain

Subdomains

Dependencies

  • ../core/errors/index.js
  • ../types/public/internal.js
  • ../util.js
  • ./astro/factory.js
  • ./astro/head-and-content.js
  • ./astro/render-template.js
  • ./common.js
  • ./util.js

Frequently Asked Questions

What does render.ts do?
render.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, RenderingEngine subdomain.
What functions are defined in render.ts?
render.ts defines 6 function(s): bufferHeadContent, callComponentAsTemplateResultOrResponse, renderToAsyncIterable, renderToReadableStream, renderToString, toPromise.
What does render.ts depend on?
render.ts imports 8 module(s): ../core/errors/index.js, ../types/public/internal.js, ../util.js, ./astro/factory.js, ./astro/head-and-content.js, ./astro/render-template.js, ./common.js, ./util.js.
Where is render.ts in the architecture?
render.ts is located at packages/astro/src/runtime/server/render/astro/render.ts (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/astro/src/runtime/server/render/astro).

Analyze Your Own Codebase

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

Try Supermodel Free