Skip to content

Dehydrated data is too late to construct client rewrite #7634

@alex35mil

Description

@alex35mil

Which project does this relate to?

Router

Describe the bug

Scenario

The app needs tenant/site routing config before router matching, because public URLs are rewritten to internal route IDs.

In the reproduction repro below:

public URL:   /guides/foo
internal URL: /live/docs/$moduleId/pages/$slug

On the server, tenant routing config is available before createRouter() and rewrite.input maps the public URL to the internal route. SSR succeeds.

The same routing config is returned from dehydrate(). On the client, however, hydrate(dehydratedData) runs after the first client match. The client router is created before that data is available, so it cannot construct the same rewrite config before matchRoutes().

Complete minimal reproducer

https://github.com/alex35mil/tanstack-dehydratedData

Steps to Reproduce the Bug

pnpm install
pnpm dev

Open:

http://127.0.0.1:3000/guides/foo

The client creates the router without rewrite because hydrate(dehydratedData) has not run yet. The first client match uses /guides/foo directly instead of the rewritten internal route, causing a hydration/matching mismatch. In the reported app this throws:

Invariant failed: Expected to find a match below the root match in SPA mode.

Expected behavior

There should be a supported way to access router dehydrated data before creating the client router, so the client can build createRouter({ rewrite }) with the same tenant routing config that SSR used.

Screenshots or Videos

No response

Platform

  • Router / Start Version:
    "@tanstack/react-router": "1.168.10",
    "@tanstack/react-start": "1.167.16",
  • OS: macOS
  • Browser: Arc
  • Browser Version: 1.146.0
  • Bundler: vite
  • Bundler Version:
    "vite": "8.0.8",

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions