TanStackT
TanStack3mo ago
14 replies
primary-violet

beforeLoad and pendingComponent behaviour

could someone help me understand how exactly does this work, in the docs I saw the below explaination for beforeLoad

If this function returns a promise, the route will be put into a pending state and cause rendering to suspend until the promise resolves. If this route's pendingMs threshold is reached, the pendingComponent will be shown until it resolves. If the promise rejects, the route will be put into an error state and the error will be thrown during render.
(https://tanstack.com/router/latest/docs/framework/react/api/router/RouteOptionsType#beforeload-method)

I tried to debug and understand using console logs, it so happens, the execution happens in this order
1. before starts executing
2. pending component
3. component
4. pending component

I was not expecting component to be rendered before pending state has finished. since that is causing subtle issues, also not matching with docs currently.
Was this page helpful?