Home / File/ jsx.ts — astro Source File

jsx.ts — astro Source File

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

File typescript CoreAstro RenderingEngine 7 imports 4 functions

Entity Profile

Dependency Diagram

graph LR
  f6e39b43_58a2_4ca6_30bf_a01e3e031e49["jsx.ts"]
  671eee89_efd6_e4f2_d203_7a62c4c09460["../../jsx-runtime/index.js"]
  f6e39b43_58a2_4ca6_30bf_a01e3e031e49 --> 671eee89_efd6_e4f2_d203_7a62c4c09460
  10d4e39f_edb6_3e34_aa93_ae1211e7da05["../types/public/internal.js"]
  f6e39b43_58a2_4ca6_30bf_a01e3e031e49 --> 10d4e39f_edb6_3e34_aa93_ae1211e7da05
  9e624f62_bcfa_4352_e9a0_dd454823f706["../../runtime/server/index.js"]
  f6e39b43_58a2_4ca6_30bf_a01e3e031e49 --> 9e624f62_bcfa_4352_e9a0_dd454823f706
  132e77ba_f68f_16dc_a64d_edda31b820dc["./astro/factory.js"]
  f6e39b43_58a2_4ca6_30bf_a01e3e031e49 --> 132e77ba_f68f_16dc_a64d_edda31b820dc
  3e244973_9bb3_86d6_0270_a57134b6266f["./component.js"]
  f6e39b43_58a2_4ca6_30bf_a01e3e031e49 --> 3e244973_9bb3_86d6_0270_a57134b6266f
  ff0be6cd_e34f_b283_f541_4038fdcadce5["./instruction.js"]
  f6e39b43_58a2_4ca6_30bf_a01e3e031e49 --> ff0be6cd_e34f_b283_f541_4038fdcadce5
  624e5f97_7f83_f926_3407_b10786361e90["./slot.js"]
  f6e39b43_58a2_4ca6_30bf_a01e3e031e49 --> 624e5f97_7f83_f926_3407_b10786361e90
  style f6e39b43_58a2_4ca6_30bf_a01e3e031e49 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { AstroJSX, type AstroVNode, isVNode } from '../../jsx-runtime/index.js';
import type { SSRResult } from '../../types/public/internal.js';
import {
	escapeHTML,
	HTMLString,
	markHTMLString,
	spreadAttributes,
	voidElementNames,
} from './index.js';
import { isAstroComponentFactory } from './render/astro/factory.js';
import { renderComponentToString } from './render/component.js';
import type { RenderInstruction } from './render/instruction.js';
import { mergeSlotInstructions, SlotString } from './render/slot.js';

const ClientOnlyPlaceholder = 'astro-client-only';

// If the `vnode.type` is a function, we could render it as JSX or as framework components.
// Inside `renderJSXNode`, we first try to render as framework components, and if `renderJSXNode`
// is called again while rendering the component, it's likely that the `astro:jsx` is invoking
// `renderJSXNode` again (loop). In this case, we try to render as JSX instead.
//
// This Symbol is assigned to `vnode.props` to track if it had tried to render as framework components.
// It mutates `vnode.props` to be able to scope to the current render call.
const hasTriedRenderComponentSymbol = Symbol('hasTriedRenderComponent');

export async function renderJSX(result: SSRResult, vnode: any): Promise<any> {
	// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
	switch (true) {
		case vnode instanceof HTMLString:
			if (vnode.toString().trim() === '') {
				return '';
			}
			return vnode;
		case typeof vnode === 'string':
			return markHTMLString(escapeHTML(vnode));
		case typeof vnode === 'function':
			return vnode;
		case !vnode && vnode !== 0:
			return '';
		case Array.isArray(vnode): {
			const renderedItems = await Promise.all(vnode.map((v: any) => renderJSX(result, v)));
			// Collect instructions from SlotString items to preserve hydration scripts
			let instructions: RenderInstruction[] | null = null;
			let content = '';
			for (const item of renderedItems) {
				if (item instanceof SlotString) {
					content += item;
					instructions = mergeSlotInstructions(instructions, item);
				} else {
					content += item;
				}
			}
			if (instructions) {
				return markHTMLString(new SlotString(content, instructions));
			}
			return markHTMLString(content);
		}
	}

	return renderJSXVNode(result, vnode);
// ... (152 more lines)

Domain

Subdomains

Dependencies

  • ../../jsx-runtime/index.js
  • ../../runtime/server/index.js
  • ../types/public/internal.js
  • ./astro/factory.js
  • ./component.js
  • ./instruction.js
  • ./slot.js

Frequently Asked Questions

What does jsx.ts do?
jsx.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 jsx.ts?
jsx.ts defines 4 function(s): prerenderElementChildren, renderElement, renderJSX, renderJSXVNode.
What does jsx.ts depend on?
jsx.ts imports 7 module(s): ../../jsx-runtime/index.js, ../../runtime/server/index.js, ../types/public/internal.js, ./astro/factory.js, ./component.js, ./instruction.js, ./slot.js.
Where is jsx.ts in the architecture?
jsx.ts is located at packages/astro/src/runtime/server/jsx.ts (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/astro/src/runtime/server).

Analyze Your Own Codebase

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

Try Supermodel Free