TanStackT
TanStack3w ago
6 replies
full-green

"window is not defined" with spa mode loader prefetch

I'm in SPA mode and prefetching data inside my loaders (see photo). The app is deployed on Vercel.

The query client options rely on an api client that uses window to get the session token from Clerk.

I'm also using a tanstack query persister with IndexedDB.

On the deployed version of the site, I'm seeing "window is not defined" if i have nothing in indexedDB e.g initial load.

From what I could see in the docs, loaders in SPA mode should run on the client unless they are the _root loader (which this isn't). Since I can't replicate this locally, Is there something i'm misunderstanding about how loaders behave when deployed and maybe specifically for Vercel?
Screenshot_2025-12-22_at_11.51.56.png
Was this page helpful?