Skip to content

Preserving middleware-set status drops middleware-set headers #7647

Open

Description

@alex35mil

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions