Server rendering
Copy pageA placeholder rendered on the server reserves its space in the first HTML, so the page doesn’t jump when JavaScript arrives. When the components register in the browser, they take over the same elements.
The React components render their placeholder markup and styles on the server automatically. Render the same state on the server and in the first client render, so hydration matches. See React and Next.js.
Native
Section titled “Native”renderStatic from dotquilt/server returns a loader’s HTML as a string. It runs anywhere: Node, Bun, Deno or an edge function. It draws only Dotquilt’s own decoration; your content comes from your own template.
import { renderStatic } from 'dotquilt/server';
const escapeHtml = (text: string) => text.replace( /[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"' })[c] ?? ''', );
/** * Server-renders the revenue card: the region and its placeholder come from * Dotquilt, your content from your own template. Works in Node, Bun or Deno. */export function revenueCard(revenue: string | null, nonce?: string): string { // The same policy as your Content-Security-Policy header, for the region // and its placeholder alike. const stylePolicy = { mode: 'inline' as const, ...(nonce ? { nonce } : {}) }; const region = renderStatic({ kind: 'region', state: revenue === null ? 'pending' : 'ready', label: 'Revenue this month', placeholder: { kind: 'skeleton-text', lines: 2, stylePolicy }, stylePolicy, }); const content = `<article class="card"><h2>Revenue</h2><p>${escapeHtml( revenue ?? '', )}</p></article>`; // Your content goes inside the region, after the placeholder. return region.replace('</dotquilt-region>', `${content}</dotquilt-region>`);}Then register the components in the browser, as usual. The region continues from the state the server rendered.
kind |
Fields |
|---|---|
region |
state, label, placeholder (any loader below) |
skeleton-block, skeleton-line, skeleton-circle |
|
skeleton-text |
lines, widths |
text-loader |
text, mask, state |
chart-loader |
variant |
table-loader |
rows, rowHeight, columns |
typing-dots |
count |
Every kind also takes mark, preset and stylePolicy.
Without JavaScript
Section titled “Without JavaScript”If scripts never load, a pending region keeps showing its still placeholder, and your content stays visible and usable below it. Keep a way forward that works without JavaScript, such as a link to reload the page, outside the region.
This is the default on purpose: a page whose bundle fails to load still works. The cost is a short moment, while JavaScript loads, when the placeholder and your server content show together and a screen reader can read content that isn’t final.
If you would rather hide pending content until the runtime takes over, render it with hidden and inert yourself, and remove both when it is ready. Only do this when the content has a way to appear without JavaScript, or when it is safe for it to stay hidden if scripts fail.