Astro integration that enables MDX support for creating interactive pages and components with Markdown and JSX
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Server-side rendering utilities for MDX components, providing component validation and HTML generation capabilities for server environments.
Validates whether a component is a valid MDX component that can be rendered.
/**
* Checks if a component is a valid MDX component for rendering
* @param Component - Component to check for MDX compatibility
* @param props - Component properties to pass during validation
* @param slotted - Destructured slotted content with default children and named slots
* @returns Promise resolving to boolean indicating if component is valid for rendering
*/
export async function check(
Component: any,
props: any,
{ default: children = null, ...slotted } = {}
): Promise<boolean>;The function performs these validation steps:
Usage Examples:
import { check } from "@astrojs/mdx/server.js";
// Check a basic component
const isValid = await check(MyMDXComponent, { title: "Hello" });
// Check with slots (using destructuring pattern)
const isValidWithSlots = await check(
MyMDXComponent,
{ title: "Hello" },
{
default: "Main content",
sidebar: "Sidebar content"
}
);
// Check returns false for non-MDX components
const isInvalid = await check("not-a-component", {});Renders an MDX component to static HTML markup for server-side rendering.
/**
* Renders MDX component to static HTML markup
* @param this - Render context with result property
* @param Component - MDX component to render
* @param props - Component properties (defaults to empty object)
* @param slotted - Destructured slotted content with default children and named slots
* @returns Promise resolving to object containing rendered HTML string
*/
export async function renderToStaticMarkup(
this: any,
Component: any,
props = {},
{ default: children = null, ...slotted } = {}
): Promise<{ html: string }>;The rendering process:
Usage Examples:
import { renderToStaticMarkup } from "@astrojs/mdx/server.js";
// Basic rendering
const result = await renderToStaticMarkup(MyMDXComponent, {
title: "Welcome",
content: "Hello World"
});
console.log(result.html); // "<div>Welcome</div>..."
// Rendering with slots (note: function uses 'this' context)
const resultWithSlots = await renderToStaticMarkup.call(
{ result: currentRenderResult },
MyMDXComponent,
{ title: "Welcome" },
{
default: "Main content here",
"hero-section": "Hero content",
footer: "Footer content"
}
);
// The function automatically converts slot names:
// "hero-section" becomes "heroSection" in the componentThe module exports a default renderer object that implements Astro's server-side rendering interface.
interface NamedSSRLoadedRendererValue {
/** Renderer identifier */
name: string;
/** Component validation function */
check: typeof check;
/** Static markup rendering function */
renderToStaticMarkup: typeof renderToStaticMarkup;
}
/** Default SSR renderer for MDX components */
const renderer: NamedSSRLoadedRendererValue;
export default renderer;The default renderer provides:
name: "astro:jsx"check: The component validation functionrenderToStaticMarkup: The HTML rendering functionBoth check and renderToStaticMarkup automatically process slot names by converting kebab-case to camelCase:
// Internal slot processing
const slotName = (str: string) => str.trim().replace(/[-_]([a-z])/g, (_, w) => w.toUpperCase());
// Examples:
// "hero-section" → "heroSection"
// "main_content" → "mainContent"
// "sidebar" → "sidebar" (unchanged)This ensures compatibility between HTML attribute naming conventions and JavaScript property names.
The server utilities provide enhanced error handling for MDX components:
When an error occurs during rendering of an MDX component (identified by the Symbol.for('mdx-component') marker), the error is enhanced with:
All errors maintain their original stack traces while providing additional context specific to MDX component rendering issues.
These server utilities are automatically used by Astro when:
.mdx pages during SSRThe utilities work seamlessly with Astro's component system and provide the necessary interface for MDX components to participate in server-side rendering.