T
TanStack4mo ago
rival-black

Fetching Data In ISR & Universal rendering

How is it possible to handle data fetching in ISR and universal (isomorphic) rendering when data might be fetched both on the server and the client side? data can be loaded: On the server side during the initial page rendering On the client side during client-side navigation or revalidation This raises a challenge: How is it possible to share or synchronize the data between the server-rendered initial load and client-side fetching, so the app shows consistent and up-to-date data without separate API endpoint?
6 Replies
fair-rose
fair-rose4mo ago
Data should be hydrated from server > Client. After that you can use TanstackQuery for example to invalidate or data or making it stale to fetch again after a certain period
rival-black
rival-blackOP4mo ago
I think either I didn’t understand your point, or you didn’t understand mine. My point is not about transferring data from server to client during the initial load. I’m talking about when using universal rendering In such cases, if we use server-side functions inside the loaders, then depending on how the page is loaded, the user might receive two different results: • An HTML response (with possibly cached server-rendered content), or • A JSON response (from a client-side navigation using fetch) And because of caching, timing, or revalidation differences, these two can be out of sync, causing the user to see different versions of the same page depending on how they navigated to it.
fair-rose
fair-rose4mo ago
Ahh right, sorry its early around here :p right, got it, because in theory after the initial server request it hits a different endpoint so the data / response might just return different results. 👍
rival-black
rival-blackOP4mo ago
No worries at all! 😄 It’s just that handling this situation — and the fact that I can’t really think of a good solution — is kind of frustrating.
fair-rose
fair-rose4mo ago
I think neither Next solves this? Does it? Because after the initial render you still also hit a RSC endpoint ( different urls )
rival-black
rival-blackOP4mo ago
not really — because RSCs are rendered only on the server, so we actually have caching control there. data fetching always happens on the server in RSCs, @Tanner Linsley got a sec?

Did you find this page helpful?