T
TanStack6mo ago
conscious-sapphire

Route `loader` function called on both client and server?

Hi! I'm coming from Remix and SolidJS where data loading functions are limited to run on the server. In working with ts router, I'm seeing console.log output from the loader function on both the client (browser console) and the server (terminal). This is surprising - I'd expect to see it only on the server.
2 Replies
stormy-gold
stormy-gold6mo ago
Yes it runs in both, during SSR in the server and during navigation in the client. When using tanstack Start, if you need to call sever only login you are expected to use a serverFn. Having used remix for a while I can see how it might be confusing
conscious-sapphire
conscious-sapphireOP6mo ago
Still a little confused. The docs go so far as to make this comparison directly:
You may be familiar with getServerSideProps from Next.js or loaders from Remix/React-Router. TanStack Router has similar functionality to preload/load assets on a per-route basis in parallel allowing it to render as quickly as possible as it fetches via suspense.
I wonder how this is different from component rendering with SSR+client nav. Is the caching mechanism that's talked about in the docs? I see server functions covered in the Start docs (React only). Is there not a server only loader with Solid support. Thanks for the pointers!

Did you find this page helpful?