Skip to main content
Learn how to set up and use Server-Side Rendering (SSR) in Sonamu.

SSR Overview

TanStack Router

File-based routing Type-safe navigation

Vite SSR

Fast builds HMR support

Direct API Call

No HTTP overhead Fast response

TanStack Query

Automated Hydration Caching integration

Sonamu SSR Architecture

Sonamu implements SSR using TanStack Router + Vite.

Core Components

entry-server.generated.tsx

Entry point for rendering React on the server (auto-generated):

entry-client.tsx

Entry point for hydrating React on the client:

TanStack Router Route Structure

Root Route

File Route

Dynamic Route

Vite Configuration

SSR vs CSR

Sonamu uses a hybrid approach:

SSR Rendering (when data preloading)

Benefits:
  • Fast First Contentful Paint
  • SEO optimization
  • Immediate display of initial data

CSR Rendering (default)

Benefits:
  • Reduced server load
  • Simple implementation
  • Fast development

Development vs Production

Development Mode

  • dev all: API server integrates Vite to serve API + Web on a single port (HMR supported)
  • dev api: Runs API only. Use when Web is not needed or when running Vite separately
  • dev web: Runs Vite dev server standalone. Pass Vite options after --

Production Build

Build output:

Cautions

Cautions when using Sonamu SSR: 1. TanStack Router based: Not Next.js App Router 2. entry-server.generated.tsx is auto-generated: Don’t modify directly 3. Be careful with window object: window doesn’t exist on server 4. dateReviver required: Handles Date object serialization/deserialization 5. Use registerSSR: See next document for data preloading

Next Steps

Data Preloading

How to use registerSSR

Hydration Strategies

Hydration optimization

Cache Control

TanStack Query caching

TanStack Router Docs

Router detailed guide