Home / File/ server.ts — astro Source File

server.ts — astro Source File

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

File typescript CoreAstro RoutingSystem 4 imports 4 functions

Entity Profile

Dependency Diagram

graph LR
  8026f0af_f709_2aa5_9cc2_85bfe4d5b6b2["server.ts"]
  b4312d04_b2c6_4823_83cb_cd5c8a3e1af9["./context.js"]
  8026f0af_f709_2aa5_9cc2_85bfe4d5b6b2 --> b4312d04_b2c6_4823_83cb_cd5c8a3e1af9
  c8c6207d_9d3f_cccc_cc72_d913b624305f["./types.js"]
  8026f0af_f709_2aa5_9cc2_85bfe4d5b6b2 --> c8c6207d_9d3f_cccc_cc72_d913b624305f
  f16d8c76_2866_6150_bd14_0347b59abfe9["astro"]
  8026f0af_f709_2aa5_9cc2_85bfe4d5b6b2 --> f16d8c76_2866_6150_bd14_0347b59abfe9
  41dbb6b2_2ef8_5fd9_e7a0_ad05bd506af4["web"]
  8026f0af_f709_2aa5_9cc2_85bfe4d5b6b2 --> 41dbb6b2_2ef8_5fd9_e7a0_ad05bd506af4
  style 8026f0af_f709_2aa5_9cc2_85bfe4d5b6b2 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import type { NamedSSRLoadedRendererValue } from 'astro';
import {
	createComponent,
	generateHydrationScript,
	NoHydration,
	renderToString,
	renderToStringAsync,
	Suspense,
	ssr,
} from 'solid-js/web';
import { getContext, incrementId } from './context.js';
import type { RendererContext } from './types.js';

const slotName = (str: string) => str.trim().replace(/[-_]([a-z])/g, (_, w) => w.toUpperCase());

type RenderStrategy = 'sync' | 'async';

async function check(
	this: RendererContext,
	Component: any,
	props: Record<string, any>,
	children: any,
) {
	if (typeof Component !== 'function') return false;
	if (Component.name === 'QwikComponent') return false;
	// Svelte component renders fine by Solid as an empty string. The only way to detect
	// if this isn't a Solid but Svelte component is to unfortunately copy the check
	// implementation of the Svelte renderer.
	if (Component.toString().includes('$$payload')) return false;

	// There is nothing particularly special about Solid components. Basically they are just functions.
	// In general, components from other frameworks (eg, MDX, React, etc.) tend to render as "undefined",
	// so we take advantage of this trick to decide if this is a Solid component or not.

	let html: string | undefined;
	try {
		const result = await renderToStaticMarkup.call(this, Component, props, children, {
			// The purpose of check() is just to validate that this is a Solid component and not
			// React, etc. We should render in sync mode which should skip Suspense boundaries
			// or loading resources like external API calls.
			renderStrategy: 'sync' as RenderStrategy,
		});
		html = result.html;
	} catch {}

	return typeof html === 'string';
}

// AsyncRendererComponentFn
async function renderToStaticMarkup(
	this: RendererContext,
	Component: any,
	props: Record<string, any>,
	{ default: children, ...slotted }: any,
	metadata?: Record<string, any>,
) {
	const ctx = getContext(this.result);
	const renderId = metadata?.hydrate ? incrementId(ctx) : '';
	const needsHydrate = metadata?.astroStaticSlot ? !!metadata.hydrate : true;
	const tagName = needsHydrate ? 'astro-slot' : 'astro-static-slot';
// ... (84 more lines)

Domain

Subdomains

Dependencies

  • ./context.js
  • ./types.js
  • astro
  • web

Frequently Asked Questions

What does server.ts do?
server.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, RoutingSystem subdomain.
What functions are defined in server.ts?
server.ts defines 4 function(s): check, renderToStaticMarkup, renderer.renderHydrationScript, slotName.
What does server.ts depend on?
server.ts imports 4 module(s): ./context.js, ./types.js, astro, web.
Where is server.ts in the architecture?
server.ts is located at packages/integrations/solid/src/server.ts (domain: CoreAstro, subdomain: RoutingSystem, directory: packages/integrations/solid/src).

Analyze Your Own Codebase

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

Try Supermodel Free