Skip to content

Route-level ssr: true ignored when defaultSsr: false — staticServerFnCache not generated #7239

Description

@fullheart

Which project does this relate to?

Start

Describe the bug

When defaultSsr: false is set in start.ts, route-level ssr: true is completely ignored. The staticServerFnCache is not generated during build, causing a 404 in the browser:

GET /__tsr/staticServerFnCache/...json 404 (Not Found)
Unexpected token '<', "<!DOCTYPE "... is not valid JSON

Why this matters: We want 100% client-first (defaultSsr: false) with selective SSG on specific routes — no SSR at request time. This bug makes that architecture impossible.

TanStack promise: The TanStack Start homepage states:

[...] Client-Side First [...]

This promise of "client-side first" with selective server-side capabilities (SSG) is broken when defaultSsr: false prevents route-level SSG from working.

Your Example Website or App

https://github.com/fullheart/tanstack-start-issue-selective-ssg

Two projects: ssg-working/ (defaultSsr: true) vs ssg-not-working/ (defaultSsr: false).

Steps to Reproduce the Bug or Issue

  1. git clone https://github.com/fullheart/tanstack-start-issue-selective-ssg.git
  2. cd ssg-not-working && npm install && npm run build
  3. Check: ls .output/public/__tsr/staticServerFnCache/directory does not exist
  4. Compare: cd ../ssg-working && npm run build && ls .output/public/__tsr/staticServerFnCache/file exists
  5. cd ../ssg-not-working && PORT=3011 npm run start
  6. Open http://localhost:3011/ssg-page in browser → you will see "Something went wrong!" and in the console:
    Failed to load resource: the server responded with a status of 404` for `__tsr/staticServerFnCache/*.json
    SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON
    

Expected behavior

  • defaultSsr: false → client-first by default for all routes
  • ssr: true on a route → that route should prerender and generate staticServerFnCache at build time
  • The staticServerFnCache/*.json should exist for routes with ssr: true

What actually happens: defaultSsr: false prevents staticServerFnCache generation entirely. Route-level ssr: true is ignored.

Platform

  • Start Version: @tanstack/react-start@1.167.42
  • Router Version: @tanstack/react-router@1.168.23
  • Static Server Functions: @tanstack/start-static-server-functions@1.166.33
  • OS: Linux
  • Bundler: Vite 8.0.9
  • Nitro: 3.0.1-20260422-085752-8c3f16b2
  • Node: 24.14.0

Additional context

Architecture goal: Client-first SPA (like Vite) with selective SSG for content routes. No SSR at request time.

start.ts (broken):

export const startInstance = createStart(() => ({
  defaultSsr: false
}));

ssg-page.tsx:

const fetchPost = createServerFn({ method: "GET" })
  .middleware([staticFunctionMiddleware])
  .handler(async () => {
    const res = await fetch("https://jsonplaceholder.typicode.com/posts/1");
    return await res.json();
  });

export const Route = createFileRoute("/ssg-page")({
  ssr: true,
  beforeLoad: async () => {
    const data = await fetchPost();
    return { postData: data };
  },
  component: SsgPage
});

Workaround: Set defaultSsr: true globally, but this forces SSR on all routes and defeats the purpose.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions