renderApplication
Render a React or Preact application document with root data and streaming hydration.
Compatibility
Import from @kasperrt/smolter/react/server @kasperrt/smolter/preact/server
Signature
function renderApplication(
request: Request,
routes: AppRoute[],
rootModule: RootModule,
entry: string,
options: RenderApplicationOptions = {},
): Promise<Response>;Parameters
Pass request, server routes, root module, browser entry URL and optional { nonce, earlyHydration } for streaming scripts under CSP.
Returns
Returns a Promise<Response> with a streaming HTML body, or a redirect/resource response. Root and matched-route loaders start concurrently. Top-level loader promises determine critical data and HTTP status; nested promises remain deferred.
Usage
Import from react/server or preact/server to use the matching renderer.
import { renderApplication } from "@kasperrt/smolter/preact/server";
const response = await renderApplication(
request,
routes,
root,
"/assets/client.js",
);Page actions and hydration
For a page POST, PUT, PATCH, or DELETE, the server runs the action once before loading the page data. JSON action results become snapshot.actionData, so useActionData reads the same result during server rendering and after hydration. A data(value, { status, headers }) result preserves its status and response headers in the HTML response, including validation statuses and cookies. Returned action errors populate snapshot.error for the route boundary. Redirects and non-JSON HTTP responses are returned directly without rendering a document.
Behavior and limits
React application SSR requires React and React DOM 19+. Preact requires preact-render-to-string >=6.8.1. In React, render a stable deferred promise with use(promise) inside Suspense and an error boundary; in Preact, use Await with its fallback prop. By default, hydration waits for document completion. earlyHydration: true hydrates shell controls while deferred values stream. Errors after headers are sent cannot change HTTP status. Vite development HTML transformation buffers; production Node/Express hosting streams. Each request router is disposed on completion or cancellation.