Skip to content

fix(vite): respect tanstack start route manifest in dev#4274

Draft
pi0 wants to merge 2 commits into
mainfrom
fix/vite-tss-routes
Draft

fix(vite): respect tanstack start route manifest in dev#4274
pi0 wants to merge 2 commits into
mainfrom
fix/vite-tss-routes

Conversation

@pi0
Copy link
Copy Markdown
Member

@pi0 pi0 commented May 20, 2026

Fixes the TanStack Start regression reported in TanStack/router#7403 (specifically this comment): <img src="/api/.../thumbnail"> returns 404 text/html in dev, even though hitting the URL directly works.

Why #4272 was not enough

#4272 made the dev middleware consult nitro.routing.routes to decide whether a request is an explicit user route. But TanStack Start API routes live at src/routes/api/**.ts and register via viteDevServer.middlewares.use(...), so they never appear in nitro.routing.routes — that table only contains the SSR catch-all /**. As a result, isExplicitRoute is always false for Start API routes, and any image-context request (Sec-Fetch-Dest: image) falls into the asset branch and is claimed by Vite.

Fix

  • During dev, consult globalThis.TSS_ROUTES_MANIFEST (published by @tanstack/start-plugin-core's routes-manifest-plugin for sibling Vite plugins) so URLs matching a TanStack Start filesystem route are treated as explicit.
  • These requests then flow through nitro's dev middleware (where Start's devApp gets first shot) instead of being classified by the asset/page heuristic.
  • Bumps @tanstack/react-router, @tanstack/react-router-devtools, and @tanstack/react-start in the vite-ssr-tss-react example to versions that publish the manifest (separate commit).

Verification

Verified locally against examples/vite-ssr-tss-react (Start app whose API routes are not visible to nitro), with the fix toggled on/off:

Request Without fix With fix
GET /api/test (plain) 200 json 200 json
GET /api/test + Sec-Fetch-Dest: image 404 html 200 json
GET /api/files/42 + Sec-Fetch-Dest: image (parametrized \$id) 404 html 200 json
GET /api/files/foo.png + Sec-Fetch-Dest: image (.png in path param) 404 html 200 json
GET /api/nope/x + image (unmatched) 404 404
GET /favicon.ico + image (real asset) 404 404

Caveat

The probe relies on the undocumented globalThis.TSS_ROUTES_MANIFEST contract. If Start renames/removes it, the fallback silently disables and we regress to the #4272 behavior. Worth coordinating with the Start team so the contract is intentional.

pi0 added 2 commits May 20, 2026 12:33
Consult `globalThis.TSS_ROUTES_MANIFEST` (published by `@tanstack/start-plugin-core`)
during dev so URLs matching a Start route count as explicit and flow through nitro's
middleware (where Start's devApp handles them) instead of the asset/page heuristic.
@vercel
Copy link
Copy Markdown

vercel Bot commented May 20, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
nitro.build Ready Ready Preview, Comment May 20, 2026 10:35am

Request Review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 20, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

Dependency versions for TanStack packages are updated in documentation and examples. The dev middleware's explicit-route detection is extended to recognize TanStack Start routes from a manifest, bypassing the asset/route ambiguity heuristic for paths matching compiled Start route patterns.

Changes

TanStack Start Routes Integration

Layer / File(s) Summary
TanStack dependency version updates
docs/4.examples/vite-ssr-tss-react.md, examples/vite-ssr-tss-react/package.json
@tanstack/react-router, @tanstack/react-router-devtools, and @tanstack/react-start version ranges are bumped in documentation and the example's package.json.
Dev middleware explicit-route detection with Start routes manifest
src/build/vite/dev.ts
The dev middleware refactors pathname extraction and extends isExplicitRoute to also match against compiled TanStack Start route patterns from globalThis.TSS_ROUTES_MANIFEST, with matchesStartRoute() caching compiled regexes and handling trailing /$ splat routes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • nitrojs/nitro#4238: Updates dev middleware routing heuristics based on headers and route manifests.
  • nitrojs/nitro#4272: Modifies dev middleware explicit-route vs asset/navigation detection logic with Nitro route classification.
  • nitrojs/nitro#4108: Changes dev middleware routing and explicit-route decision logic for baseURL and Nitro route matching.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The pull request description clearly explains the problem being fixed (TanStack Start regression #7403), why prior fix #4272 was insufficient, the specific solution implemented, verification steps, and important caveats about undocumented API contracts.
Title check ✅ Passed The title 'fix(vite): respect tanstack start route manifest in dev' follows conventional commits format with 'fix' type and clear scope, and accurately describes the main change of respecting TanStack Start route manifests in the dev middleware.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/vite-tss-routes

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/build/vite/dev.ts (1)

310-314: ⚡ Quick win

Remove narrative inline comments in this helper block.

Line 310–314 adds explanatory comments that conflict with the repo rule for TS/JS files.

Proposed cleanup
-// ---- TanStack Start route manifest probe ----
-// Start's router plugin publishes a filesystem-routes manifest on globalThis for sibling Vite
-// plugins to consume (see `@tanstack/start-plugin-core` `routes-manifest-plugin`). When present,
-// any URL matching one of Start's routes is treated as explicit so it flows through Nitro's
-// middleware (where Start's devApp gets first shot) instead of the asset/page heuristic.
+// ---- TanStack Start route manifest probe ----

As per coding guidelines: "Do not add comments explaining what the line does unless prompted".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/build/vite/dev.ts` around lines 310 - 314, The added narrative comment
block beginning with "---- TanStack Start route manifest probe ----" should be
removed to comply with the TS/JS commenting guideline; locate the helper block
in src/build/vite/dev.ts that publishes the Start router manifest to globalThis
(the surrounding comments referencing `@tanstack/start-plugin-core` and the
filesystem-routes manifest) and delete those explanatory lines, leaving only
minimal, if any, concise tags or none at all so the code itself remains
self-descriptive.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/build/vite/dev.ts`:
- Around line 310-314: The added narrative comment block beginning with "----
TanStack Start route manifest probe ----" should be removed to comply with the
TS/JS commenting guideline; locate the helper block in src/build/vite/dev.ts
that publishes the Start router manifest to globalThis (the surrounding comments
referencing `@tanstack/start-plugin-core` and the filesystem-routes manifest)
and delete those explanatory lines, leaving only minimal, if any, concise tags
or none at all so the code itself remains self-descriptive.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: aa5b5816-bc71-4d45-9cd6-6631eead5c0c

📥 Commits

Reviewing files that changed from the base of the PR and between 9cc59cf and b8be85d.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (3)
  • docs/4.examples/vite-ssr-tss-react.md
  • examples/vite-ssr-tss-react/package.json
  • src/build/vite/dev.ts

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 20, 2026

Open in StackBlitz

npm i https://pkg.pr.new/nitro@4274

commit: b8be85d

@pi0 pi0 marked this pull request as draft May 20, 2026 10:39
@pi0 pi0 changed the title feat(vite): forward tanstack start routes through nitro middleware fix(vite): forward tanstack start routes through nitro middleware May 20, 2026
@pi0 pi0 requested a review from schiller-manuel May 20, 2026 10:53
@pi0 pi0 changed the title fix(vite): forward tanstack start routes through nitro middleware fix(vite): respect tanstack start route manifest in dev May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant