question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The variables in the cache are not identical with SSR.

See original GitHub issue

Intended 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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
negezorcommented, Sep 29, 2021

@brainkim I serialize the cache like this

JSON.stringify(cache.extract());
0reactions
bignimbuscommented, Dec 5, 2022

Somehow the linked PR didn’t automatically close this so I’ll do it manually 😃 let us know if you need more support here!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found