Server function with middleware causes serialization error when a redirect is thrown in the function handler
Which project does this relate to?
Start
Describe the bug
I get serialization errors whenever I chain a middleware to a server function and perform any redirect in that server function handler but the redirect works fine and no serialization error occurs when I remove the middleware.
export const createOrgFn = createServerFn({ method: 'POST' })
.middleware([authMiddleware])
.inputValidator(OrgFormSchema)
.handler(async ({ data }) => {
const api = await client()
const res = await api.post('/orgs/create', data)
if (res.data) {
throw redirect({
to: '/$orgSlug',
params: { orgSlug: res.data.data.organization.slug },
})
}
})
Error creating organization The value [object Response] of type "object" cannot be parsed/serialized. There are few workarounds for this problem: - Transform the value in a way that it can be serialized. - If the reference is present on multiple runtimes (isomorphic), you can use the Reference API to map the references.
Your Example Website or App
https://codesandbox.io/p/devbox/dank-morning-xdnwrm?file=%2Fsrc%2Froutes%2Fdemo%2Fstart.server-funcs.tsx%3A96%2C35
Steps to Reproduce the Bug or Issue
- Create a server function
- Chain a request middleware to that function
- Throw a redirect in the handler of that server function
Expected behavior
I expect the redirect to work fine and no serialization error.
Screenshots or Videos
No response
Platform
- Router / Start Version: [^1.134.12]
- OS: [Linux]
- Browser: [Chrome ]
- Browser Version: [91.1]
- Bundler: [vite]
- Bundler Version: [7.0.0]
Additional context
@Julius-Java If this issue is approved I would like to work on this!
We are experiencing this as well.
Just a note, after updating to 1.139.3 this still doesn't work but the error is different:
Server Fn Error!
E [Error]: Seroval Error (specific: 1)
We are experiencing this as well.
Just a note, after updating to 1.139.3 this still doesn't work but the error is different:
Server Fn Error! E [Error]: Seroval Error (specific: 1)
Have you been able to fix it?