router icon indicating copy to clipboard operation
router copied to clipboard

Can't redirect in server functions with middleware

Open jperasmus opened this issue 6 months ago • 0 comments

Which project does this relate to?

Start

Describe the bug

Throwing redirects in server functions that use middleware doesn't work. It works fine if I remove the middleware. I am using the useServerFn() helper hook on the client.

The problem seems to be that the isRedirect() helper from @tanstack/router-core expects the response to be a type of Response with an options prop.

When using middleware, the response is a plain object.

Your Example Website or App

https://codesandbox.io/p/devbox/thirsty-gould-yc3fks

Steps to Reproduce the Bug or Issue

  1. Click the button "With middleware (not working)" - notice no redirect
  2. Click the button "Without middleware (working)" - you get redirected to the /posts page

Expected behavior

I expect that redirects within server functions work regardless of whether I use middleware or not.

Screenshots or Videos

No response

Platform

I believe it is platform agnostic.

Additional context

No response

jperasmus avatar Jun 18 '25 20:06 jperasmus