Lazy loading component: `Error in renderToPipeableStream: ReferenceError: window is not defined`
When loading that component:
I get this error:
Error in renderToPipeableStream: ReferenceError: window is not defined
I'd expect since I am lazy loading it, the server would know that it shouldn't be rendered on server side so I am confused 🤔4 Replies
deep-jade•6mo ago
hm I think this also executes on the server
deep-jade•6mo ago
you would need to either set ssr:false for that route, or use a component wrapper like this:
https://github.com/sergiodxa/remix-utils/blob/main/src/react/client-only.tsx
GitHub
remix-utils/src/react/client-only.tsx at main · sergiodxa/remix-utils
A set of utility functions and types to use with Remix.run - sergiodxa/remix-utils
metropolitan-bronzeOP•6mo ago
OK good to know thank you so much!
What worked for me, also wrapping it with Suspense:
manual-pink•4mo ago
there is a better solution - ClientOnly component - https://tanstack.com/router/latest/docs/framework/react/api/router/clientOnlyComponent