The variables in the cache are not identical with SSR.
See original GitHub issueIntended outcome:
The variables in the cache are identical to those retrieved using SSR.
Actual outcome:
The variables in cache are sorted in a different order. The apollo client does not find the cache and makes new requests. If you look at the ROOT_QUERY cache through the Apollo Client Devtools, there will be two different keys:
// After cache.extract().ROOT_QUERY['...']
teams({"activity":{"include":[],"exclude":[]},"contributor":{"include":[],"exclude":[]},"first":20,"orderBy":{"field":"UPDATED_AT","direction":"DESC"}})
// After hydration in the client
teams({"activity":{"include":[],"exclude":[]},"contributor":{"include":[],"exclude":[]},"first":20,"orderBy":{"field":"UPDATED_AT","direction":"DESC"}})
teams({"activity":{"exclude":[],"include":[]},"contributor":{"exclude":[],"include":[]},"first":20,"orderBy":{"direction":"DESC","field":"UPDATED_AT"}})
const cache = new InMemoryCache({});
if (!isServer) {
cache.restore(JSON.parse(window.__APOLLO_STATE__));
}
const apolloClient = new ApolloClient({
link,
cache,
ssrMode: isServer,
ssrForceFetchDelay: 1000,
connectToDevTools: process.env.NODE_ENV !== 'production'
});
const { result } = useFetchTeamsQuery({
activity: {
include: [],
exclude: []
},
contributor: {
include: [],
exclude: []
},
first: 20,
orderBy: {
field: 'UPDATED_AT',
direction: 'DESC'
}
});
How to reproduce the issue:
Versions
System:
OS: Linux 4.19 Arch Linux
Binaries:
Node: 16.10.0 - /usr/sbin/node
Yarn: 1.22.11 - /usr/sbin/yarn
npm: 7.24.0 - /usr/sbin/npm
@apollo/client
: 3.4.15
graphql
: 15.6.0
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Query with fetchPolicy "no-cache", SSR of false performing ...
A query made with SSR={false} and fetchPolicy="no-cache"appears to be performing server side rendering. The same query with fetchPolicy="network ...
Read more >Reading and writing data to the cache - Apollo GraphQL Docs
Using GraphQL queries. You can read and write cache data using GraphQL queries that are similar (or even identical) to queries that you...
Read more >Configuring build settings - AWS Amplify Hosting
Using the envCache , we can store information on the deployed environment and make it available to the build container in successive builds....
Read more >Caching - webpack
Newer versions may not have all the same issues with hashing as some older versions, but we still recommend the following steps to...
Read more >Using environment variables in a React application
It's a good idea to keep the same convention even when not using create-react-app, it just makes it really obvious where this value...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@brainkim I serialize the cache like this
Somehow the linked PR didn’t automatically close this so I’ll do it manually 😃 let us know if you need more support here!