Is there a way to attach stuff to "window.__stuff__" during SSR?
I'm wondering if it's possible to have the root route contain
Is this possible?
8 Replies
jolly-crimson•3d ago
Have you tried using the
scripts options in the route?
What is your use case?logical-cyanOP•3d ago
let me try that
My use case is that I'm managing my auth session on the server side, before any HTML or javascript is downloaded to the client at all. I want to inject some info about the user onto the window so the client-side doesn't need to re-fetch it.
correct-apricot•2d ago
Are you by any chance using TanStack Query? The query cache can be populated on the server, you can use it server-side while rendering, and then the query cache + html is sent to the client, the client won't have to do any extra fetches because the query cache already has the data
logical-cyanOP•2d ago
I am not using query yet, but I thought this should have been pretty easy in start without needing to integrate more libs
stormy-gold•2d ago
how do you consume this injected "stuff"?
logical-cyanOP•2d ago
In
__root.tsx:
logical-cyanOP•2d ago
upon further reading I found this: https://tanstack.com/router/latest/docs/framework/react/guide/ssr#rendering-the-application-on-the-server
SSR | TanStack Router React Docs
[!WARNING] While every effort has been made to separate these APIs from changes to Tanstack Start, there are underlying shared implementations internally. Therefore these can be subject to change and...
logical-cyanOP•2d ago
So now I'm thinking I can do this?