Skip to content

Can't redirect in server functions with middleware #4460

Open
@jperasmus

Description

@jperasmus

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions