server.ts — astro Source File
Architecture documentation for server.ts, a typescript file in the astro codebase. 4 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 90e6a33a_3784_88f7_7685_7a18e74859af["server.ts"] f16d8c76_2866_6150_bd14_0347b59abfe9["astro"] 90e6a33a_3784_88f7_7685_7a18e74859af --> f16d8c76_2866_6150_bd14_0347b59abfe9 b77270e1_f0f2_7ea7_00a0_eedcb9ad6bdb["errors"] 90e6a33a_3784_88f7_7685_7a18e74859af --> b77270e1_f0f2_7ea7_00a0_eedcb9ad6bdb 5cb493ec_f3a5_3354_a1cd_243d52fecf7f["jsx-runtime"] 90e6a33a_3784_88f7_7685_7a18e74859af --> 5cb493ec_f3a5_3354_a1cd_243d52fecf7f 21c9aedb_261f_6744_350a_486c989130ae["index.js"] 90e6a33a_3784_88f7_7685_7a18e74859af --> 21c9aedb_261f_6744_350a_486c989130ae style 90e6a33a_3784_88f7_7685_7a18e74859af fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import type { NamedSSRLoadedRendererValue } from 'astro';
import { AstroError } from 'astro/errors';
import { AstroJSX, jsx } from 'astro/jsx-runtime';
import { renderJSX } from 'astro/runtime/server/index.js';
const slotName = (str: string) => str.trim().replace(/[-_]([a-z])/g, (_, w) => w.toUpperCase());
// NOTE: In practice, MDX components are always tagged with `__astro_tag_component__`, so the right renderer
// is used directly, and this check is not often used to return true.
export async function check(
Component: any,
props: any,
{ default: children = null, ...slotted } = {},
) {
if (typeof Component !== 'function') return false;
const slots: Record<string, any> = {};
for (const [key, value] of Object.entries(slotted)) {
const name = slotName(key);
slots[name] = value;
}
try {
const result = await Component({ ...props, ...slots, children });
return result[AstroJSX];
} catch (e) {
throwEnhancedErrorIfMdxComponent(e as Error, Component);
}
return false;
}
export async function renderToStaticMarkup(
this: any,
Component: any,
props = {},
{ default: children = null, ...slotted } = {},
) {
const slots: Record<string, any> = {};
for (const [key, value] of Object.entries(slotted)) {
const name = slotName(key);
slots[name] = value;
}
const { result } = this;
try {
const html = await renderJSX(result, jsx(Component, { ...props, ...slots, children }));
return { html };
} catch (e) {
throwEnhancedErrorIfMdxComponent(e as Error, Component);
throw e;
}
}
function throwEnhancedErrorIfMdxComponent(error: Error, Component: any) {
// if the exception is from an mdx component
// throw an error
if (Component[Symbol.for('mdx-component')]) {
// if it's an existing AstroError, we don't need to re-throw, keep the original hint
if (AstroError.is(error)) return;
// Mimic the fields of the internal `AstroError` class (not from `astro/errors`) to
// provide better title and hint for the error overlay
(error as any).title = error.name;
(error as any).hint =
`This issue often occurs when your MDX component encounters runtime errors.`;
throw error;
}
}
const renderer: NamedSSRLoadedRendererValue = {
name: 'astro:jsx',
check,
renderToStaticMarkup,
};
export default renderer;
Domain
Subdomains
Dependencies
- astro
- errors
- index.js
- jsx-runtime
Source
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, slotName, throwEnhancedErrorIfMdxComponent.
What does server.ts depend on?
server.ts imports 4 module(s): astro, errors, index.js, jsx-runtime.
Where is server.ts in the architecture?
server.ts is located at packages/integrations/mdx/src/server.ts (domain: CoreAstro, subdomain: RoutingSystem, directory: packages/integrations/mdx/src).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free