Redirects within prefetching using TanStack Query don't work
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 15.1k
- Forks
- 1.9k
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 143
Description
Which project does this relate to?
Start
Describe the bug
Redirects called by a server function that is called by TanStack Query in a loader prefetch should redirect, but instead causes a serialization (Seroval) error. The documentation implies it should(?) work.
Your Example Website or App
https://github.com/CarelessInternet/tanstack-start-serializaton-repro
Steps to Reproduce the Bug or Issue
- Go to the index route.
index.tsx:
const getData = createServerFn({ method: 'GET' })
.handler(() => {
throw redirect({ to: '/about' })
});
const options = queryOptions({
queryKey: ['data'],
queryFn: () => getData(),
});
export const Route = createFileRoute('/')({
component: App,
loader: async () => await queryClient.prefetchQuery(options),
});
- Check the terminal.
Output:
Serialization error: 1 | var L=(i=>(i[i.AggregateError=1]="AggregateError",i[i.ArrowFunction=2]="ArrowFunction",i[i.ErrorPrototypeStack=4]="ErrorPrototypeStack",i[i.ObjectAssign=8]="ObjectAssign",i[i.BigIntTypedArray=16]="BigIntTypedArray",i[i.RegExp=32]="RegExp",i))(L||{});var v=Symbol.asyncIterator,mr=Symbol.hasInstance,R=Symbol.isConcatSpreadable,C=Symbol.iterator,pr=Symbol.match,dr=Symbol.matchAll,gr=Symbol.replace,yr=Symbol.search,Nr=Symbol.species,br=Symbol.split,vr=Symbol.toPrimitive,P=Symbol.toStringTag,Cr=Symbol.unscopables;var rt={0:"Symbol.asyncIterator",1:"Symbol.hasInstance",2:"Symbol.isConcatSpreadable",3:"Symbol.iterator",4:"Symbol.match",5:"Symbol.matchAll",6:"Symbol.replace",7:"Symbol.search",8:"Symbol.species",9:"Symbol.split",10:"Symbol.toPrimitive",11:"Symbol.toStringTag",12:"Symbol.unscopables"},ve={[v]:0,[mr]:1,[R]:2,[C]:3,[pr]:4,[dr]:5,[gr]:6,[yr]:7,[Nr]:8,[br]:9,[vr]:10,[P]:11,[Cr]:12},tt={0:v,1:mr,2:R,3:C,4:pr,5:dr,6:gr,7:yr,8:Nr,9:br,10:vr,11:P,12:Cr},nt={2:"!0",3:"!1",1:"void 0",0:"null",4:"-0",5:"1/0",6:"- | ... truncated
2 | `:return"\\n";case"\r":return"\\r";case"\b":return"\\b";case" ":return"\\t";case"\f":return"\\f";case"<":return"\\x3C";case"\u2028":return"\\u2028";case"\u2029":return"\\u2029";default:return o}}function y(e){let r="",t=0,n;for(let a=0,s=e.length;a<s;a++)n=fn(e[a]),n&&(r+=e.slice(t,a)+n,t=a+1);return t===0?r=e:r+=e.slice(t),r}function Sn(e){switch(e){case"\\\\":return"\\";case'\\"':return'"';case"\\n":return`
3 | `;case"\\r":return"\r";case"\\b":return"\b";case"\\t":return" ";case"\\f":return"\f";case"\\x3C":return"<";case"\\u2028":return"\u2028";case"\\u2029":return"\u2029";default:return e}}function D(e){return e.replace(/(\\\\|\\"|\\n|\\r|\\b|\\t|\\f|\\u2028|\\u2029|\\x3C)/g,Sn)}var U="__SEROVAL_REFS__",ce="$R",Ie=`self.${ce}`;function mn(e){return e==null?`${Ie}=${Ie}||[]`:`(${Ie}=${Ie}||{})["${y(e)}"]=[]`}var Ar=new Map,j=new Map;function pn(e,r){return Ar.set(r,e),j.set(e,r),r}function Er(e){return Ar.has(e)}function dn(e){return j.has(e)}function ct(e){if(Er(e))return Ar.get(e);throw new Re(e)}function ft(e){if(dn(e))return j.get(e);throw new Pe(e)}typeof globalThis!="undefined"?Object.defineProperty(globalThis,U,{value:j,configurable:!0,writable:!1,enumerable:!1}):typeof window!="undefined"?Object.defineProperty(window,U,{value:j,configurable:!0,writable:!1,enumerable:!1}):typeof self!="undefined"?Object.defineProperty(self,U,{value:j,configurable:!0,writable:!1,enumerable:!1}):typeof global!="undefined"&&Obje | ... truncated
error: Seroval Error (specific: 1)
value: Response (0 KB) {
ok: false,
url: "",
status: 307,
statusText: "",
headers: Headers {},
redirected: false,
bodyUsed: false
},
at Da (/workspaces/node_modules/seroval/dist/esm/production/index.mjs:3:31653)
at Jr (/workspaces/node_modules/seroval/dist/esm/production/index.mjs:3:28561)
at Wr (/workspaces/node_modules/seroval/dist/esm/production/index.mjs:3:28874)
at Jr (/workspaces/node_modules/seroval/dist/esm/production/index.mjs:3:28561)
at Wr (/workspaces/node_modules/seroval/dist/esm/production/index.mjs:3:28874)
at ba (/workspaces/node_modules/seroval/dist/esm/production/index.mjs:3:28377)
at va (/workspaces/node_modules/seroval/dist/esm/production/index.mjs:3:28440)
at Jr (/workspaces/node_modules/seroval/dist/esm/production/index.mjs:3:28561)
at Wr (/workspaces/node_modules/seroval/dist/esm/production/index.mjs:3:28874)
at Jr (/workspaces/node_modules/seroval/dist/esm/production/index.mjs:3:28561)
at Wr (/workspaces/node_modules/seroval/dist/esm/production/index.mjs:3:28874)
at Jr (/workspaces/node_modules/seroval/dist/esm/production/index.mjs:3:28561)
at Wr (/workspaces/node_modules/seroval/dist/esm/production/index.mjs:3:28874)
at G (/workspaces/node_modules/seroval/dist/esm/production/index.mjs:3:32851)
at Qr (/workspaces/node_modules/seroval/dist/esm/production/index.mjs:3:32910)
at cn (/workspaces/node_modules/seroval/dist/esm/production/index.mjs:3:34151)
at <anonymous> (/workspaces/node_modules/@tanstack/router-core/dist/esm/ssr/ssr-server.js:174:4)
Expected behavior
The user should be redirected to the route /about.
Screenshots or Videos
No response
Platform
- Router / Start Version: 1.168.10/1.167.16
- OS: Linux
- Browser: Zen (Firefox)
- Browser Version: 1.19.5b
- Bundler: Vite
- Bundler Version: 8.0.8
Additional context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the index.tsx reproduction in the linked example and run the loader prefetch flow, checking the terminal output for the Seroval error. Trace the redirect through the server-side stack entry in @tanstack/router-core/dist/esm/ssr/ssr-server.js; done means the index route redirects to /about without a serialization error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript, vite
- Domain
- backend, web-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100