TanStack / TanStack/router

Preserving middleware-set status drops middleware-set headers

Open
#7,647 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

response-reconciliation
Dominant language
TypeScript
Stars
15.1k
Forks
1.9k
Avg merge
1d 20h
Merged PRs (30d)
143

Description

Which project does this relate to?

Start

Describe the bug

I have a request middleware that classifies a document request, sets setResponseStatus(410) and setResponseHeader("cache-control", "no-store"), then continues into the router so the normal React shell/error UI renders.

To preserve the middleware status, I wrap defaultStreamHandler and rebuild the response with getResponseStatus(). That preserves the status, but middleware-set headers disappear from the final document response. Route headers still work.

More details are in the repro repo.

Complete minimal reproducer

https://github.com/alex35mil/tanstack-start-middleware-response-headers

Steps to Reproduce the Bug
pnpm install
pnpm dev
curl -i http://127.0.0.1:3000/
Expected behavior

The final document response preserves both the middleware-classified status and headers:

HTTP/1.1 418
x-route-header: present
x-middleware-header: present
Screenshots or Videos

No response

Platform
  • Router / Start Version:
    "@tanstack/react-router": "1.170.15",
    "@tanstack/react-start": "1.168.25",
    "@vitejs/plugin-react": "6.0.2",
  • OS: macOS
  • Browser: Arc
  • Browser Version: 1.146.0
  • Bundler: vite
  • Bundler Version: 8.0.16
Additional context

Additional context is in the repro repo.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked reproducer: run pnpm install, pnpm dev, and curl -i http://127.0.0.1:3000/. Trace the defaultStreamHandler wrapper, getResponseStatus(), and middleware response handling; done means the document response preserves both the middleware-set status and headers while retaining the route header.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript, vite
Domain
backend-api-design, full-stack, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.