diff --git a/examples/with-apollo-and-redux/lib/apollo.js b/examples/with-apollo-and-redux/lib/apollo.js index e587dcd1607ed..0b21a60a090a4 100644 --- a/examples/with-apollo-and-redux/lib/apollo.js +++ b/examples/with-apollo-and-redux/lib/apollo.js @@ -29,7 +29,11 @@ export function initializeApollo(initialState = null) { // If your page has Next.js data fetching methods that use Apollo Client, the initial state // get hydrated here if (initialState) { - _apolloClient.cache.restore(initialState) + // Get existing cache, loaded during client side data fetching + const existingCache = _apolloClient.extract() + // Restore the cache using the data passed from getStaticProps/getServerSideProps + // combined with the existing cached data + _apolloClient.cache.restore({ ...existingCache, ...initialState }) } // For SSG and SSR always create a new Apollo Client if (typeof window === 'undefined') return _apolloClient diff --git a/examples/with-apollo/lib/apolloClient.js b/examples/with-apollo/lib/apolloClient.js index d17f55dc9f839..eada4de6cd111 100644 --- a/examples/with-apollo/lib/apolloClient.js +++ b/examples/with-apollo/lib/apolloClient.js @@ -29,7 +29,11 @@ export function initializeApollo(initialState = null) { // If your page has Next.js data fetching methods that use Apollo Client, the initial state // gets hydrated here if (initialState) { - _apolloClient.cache.restore(initialState) + // Get existing cache, loaded during client side data fetching + const existingCache = _apolloClient.extract() + // Restore the cache using the data passed from getStaticProps/getServerSideProps + // combined with the existing cached data + _apolloClient.cache.restore({ ...existingCache, ...initialState }) } // For SSG and SSR always create a new Apollo Client if (typeof window === 'undefined') return _apolloClient