T
TanStack6mo ago
absent-sapphire

Switched to client rendering because the server rendering errored:window is not defined

I am migrating to Tanstack start, and have window object used in UI lib, but I am still get this error and SSR is disabled because of this, and same for location how to solve this in Tanstack start ?
No description
10 Replies
adverse-sapphire
adverse-sapphire6mo ago
where do you use this UI lib? if in the root route, then there you currently cannot disable SSR will be made possible in future but not ready yet
absent-sapphire
absent-sapphireOP6mo ago
No I use it in my routes not root route, I use it in the navigationLayout, the issue is it switch to client rendering so no SSR now, and actually why I get this error as it was just working dine when using tanstack router only without tanstack start, why window is now not defined ?
No description
adverse-sapphire
adverse-sapphire6mo ago
can you provide a complete example repo?
absent-sapphire
absent-sapphireOP6mo ago
This lib is private for the company, it's built with tailwind and shadcn, and I am just importing components from it. I am just have the navigation layout and in it sidebar, this sidebar uses window object, and this what cause this issue as in the first image, can't understand how this issue relates to SSR and make it switch to client Have any ideas ? like i have <SideBar/> in my layout and when remove it SSR works, so the issue in it as it uses window object. As we use SSR there is no window object as this is part of the browser environment, so this is what cause the issue
adverse-sapphire
adverse-sapphire6mo ago
well does it try to access window on the server?
absent-sapphire
absent-sapphireOP6mo ago
yes that's the issue Do you think this must be handled from tanstack start itself to not switch to client rendering in this case or I need to edit UI lib to handle this ? or may be I do something wrong ?
adverse-sapphire
adverse-sapphire6mo ago
no. you must ensure that during SSR window and stuff is not accessed
absent-sapphire
absent-sapphireOP6mo ago
so this not related to where it is called as all will be rendered in SSR, right?
adverse-sapphire
adverse-sapphire6mo ago
depends. if you disable SSR for some routes those won't be rendered on the server
absent-sapphire
absent-sapphireOP6mo ago
Ok, Thanks for help and appreciate fast response

Did you find this page helpful?