Skip to content

SSR and RSC

Snapshot SSR helpers are exported from @lastshotlabs/snapshot/ssr.

import { createReactRenderer } from "@lastshotlabs/snapshot/ssr";
const renderer = createReactRenderer({
routesDir: "./server/routes",
});

Enable the Vite transform with snapshotSsr({ rsc: true }), then pass RSC options to renderPage() where your server renderer needs them.

import {
buildComponentId,
hasUseClientDirective,
hasUseServerDirective,
renderPage,
} from "@lastshotlabs/snapshot/ssr";
import { usePrefetchRoute } from "@lastshotlabs/snapshot/ssr";
function NavLink({ href, children }: { href: string; children: React.ReactNode }) {
const prefetch = usePrefetchRoute();
return (
<a href={href} onMouseEnter={() => prefetch(href)}>
{children}
</a>
);
}
import {
createPprCache,
extractPprShell,
renderPprPage,
} from "@lastshotlabs/snapshot/ssr";
const cache = createPprCache();
const shell = await extractPprShell(<App />);
cache.set("/dashboard", shell);
const response = await renderPprPage({
cache,
url: "/dashboard",
component: <App />,
});
ScenarioUse
File-based React routescreateReactRenderer
RSC detectionhasUseClientDirective, hasUseServerDirective, buildComponentId
Route prefetchusePrefetchRoute
Partial prerenderingextractPprShell, createPprCache, renderPprPage