Skip to content

Hydration error on direct navigation to non-root routes in SPA mode #6455

@bbertold

Description

@bbertold

Which project does this relate to?

Start

Describe the bug

When deploying a TanStack Start application with spa mode enabled to Cloudflare, directly navigating to a non-root route (e.g., /example) results in a React hydration error. The same route works correctly when accessed via client-side navigation (e.g., clicking a <Link> from /).

On direct navigation to a non-root route, React throws a hydration mismatch error and the page visibly flashes:

Hydration failed because the server rendered HTML didn't match the client. 
As a result this tree will be regenerated on the client.

Error reference: https://react.dev/errors/418?args[]=HTML&args[]=

This issue appears to be directly related to Cloudflare's SPA handling configuration:

"not_found_handling": "single-page-application"

Your Example Website or App

https://github.com/bbertold/tanstack-start-spa

Steps to Reproduce the Bug or Issue

  1. Clone the reproduction repository
  2. Build the application: pnpm build
  3. Preview the build: pnpm preview
  4. Open browser and navigate directly to /example in the URL bar
  5. Press Enter
  6. Observe the hydration error in console and visible flash of content

Expected behavior

The page should load without hydration errors.

Screenshots or Videos

No response

Platform

  • Router / Start Version: 1.154.8
  • OS: macOS
  • Browser: Chrome (144.0.7559.59)
  • Bundler: Vite (7.1.7)
  • Wrangler version: 4.60.0

Additional context

No response

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