T
TanStack5mo ago
fascinating-indigo

Route preloading causing an infinite loop.

I'm running into an issue with route preloading causing an infinite loop. I'm using tanstack start and have a server function fetchSessionUser() that's used in my root route's beforeLoad to get the current user from supabase. When I hover over a <Link to="/teams/create" />, which is located in /_authed/dashboard (route: _authed/teams/create.tsx) , tanstack tries to preload the /teams/create route, and that seems to trigger the root beforeLoad (and therefore the fetchSessionUser() serverFn) repeatedly, leading to an infinite loop of requests like this in the terminal: ServerFn Request: src_routes_authed_tsx--fetchSessionUser_createServerFn_handler ServerFn Response: 200 ... (infinite loop)
No description
No description
No description
1 Reply
stormy-gold
stormy-gold5mo ago
beforeLoad receives a preload boolean argument, you could skip the redirect in that case https://tanstack.com/router/latest/docs/framework/react/api/router/RouteOptionsType#beforeload-method
RouteOptions type | TanStack Router React Docs
The RouteOptions type is used to describe the options that can be used when creating a route. RouteOptions properties The RouteOptions type accepts an object with the following properties: getParentRo...

Did you find this page helpful?