Next.js Discord

Discord Forum

Is there a way to show cached user data immediately on page load in Next.js SSR?

Answered
Cuban Crocodile posted this in #help-forum
Open in Discord
Cuban CrocodileOP
Is it possible that after fetching the user profile data once, the username can be showed immediately in the profile navbar button on future refreshes without using a skeleton placeholder while still silently fetching for fresh data in the background? I'm already caching the data, but from what I understand in Next.js SSR, the server renders the component without access to browser APIs like localStorage, so is there any solution for this?
Answered by Morelet’s Crocodile
Is it possible to put this component in the layout instead of on the page?
View full answer

3 Replies

Morelet’s Crocodile
Is it possible to put this component in the layout instead of on the page?
Answer
@Morelet’s Crocodile Is it possible to put this component in the layout instead of on the page?
Cuban CrocodileOP
Yes, that's what I ended up doing, moved the context providers to the layout and used custom DOM events to notify them when the cookies are updated, which solved the hydration and real-time update issues!
Morelet’s Crocodile
Glad it worked out for you