You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Global Middleware causes serialisation error when throwing redirects via server function #5372
When there is a global function middleware present in the start instance created in a start.ts file, and a redirect is thrown by any server function a SerovalUnsupportedTypeError occurs.
Add a file with the server function throwing redirect:
import{createServerFn}from'@tanstack/react-start';import{redirect}from'@tanstack/react-router';exportconstredirectTest=createServerFn().handler(async()=>{throwredirect({to: "/posts"})})// in a component functionHome(){constredir=useServerFn(redirectTest);return(<divclassName="p-2"><h3>Welcome Home!!!</h3><buttononClick={()=>redir()}>test redirect</button></div>)}
Expected behavior
I expected the redirect to be propagated to the client router correctly
Screenshots or Videos
Platform
Router / Start Version: 1.132.38
OS: macOS
Browser: Chrome
Browser Version: 138
Bundler: vite
Bundler Version: 7.1.1
Additional context
No response
Reacted by Ryan Gillie, Vincent Delmas, Carsten Lebek, mpa, Julian Klumpers, Mubarak Yahaya, Jonathan Chan, Godwin Pinto, Sutu Sebastian, Leandro Branco and 6 more
Same, also seeing this issue with a normal server function and [non global] middleware. This one is a bit problematic for us and will block our migration over to tanstack/start. Hoping it can be addressed in the next few weeks as stable v1 gets closer. Thanks team!
import{isRedirect}from"@tanstack/react-router";import{createMiddleware,createStart}from"@tanstack/react-start";consttempRedirectMiddleware=createMiddleware({type: "function"}).server(async({ next })=>{constresult=awaitnext();if("error"inresult&&isRedirect(result.error)){throwresult.error;}returnresult;});
Reacted by Hubert Lin, KhanhIceTea, Oguz Gelal and Parsa Shamaeezadeh
Activity
kylekz commentedon Oct 20, 2025
also seeing this using just a server function middleware attached with
.middleware([myMiddleware])rather than a global middleware, if it matterswillhoney7 commentedon Nov 3, 2025
Same, also seeing this issue with a normal server function and [non global] middleware. This one is a bit problematic for us and will block our migration over to tanstack/start. Hoping it can be addressed in the next few weeks as stable v1 gets closer. Thanks team!
willhoney7 commentedon Nov 10, 2025
Found a workaround via discord