Skip to content

Different results for server and client pages with dynamic data #1690

Answered by fivethreeo
corrideat asked this question in Q&A
Discussion options

You must be logged in to vote

The best way of doing this is to have some kind of server-side cache in a provider that stores any results from the fetches you do server-side. Then put the cached data in a script-tag. i.e window.SSRCACHE. Then have client-side cache in a provider that reads that window variable. If there is no cache value do a client-side fetch. If there is a value, use the cached data and invalidate the cache.

Now, implementering this is non-trivial. There is react-query and if you use graphql there is urql that has a normalized cache exchange.

I am working on a example of using prisma, graphql-codegen and apollo-server that uses urql.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by fivethreeo
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1687 on August 20, 2021 13:27.