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.

Hydratation bug with first render

See original GitHub issue

Hello,

I have followed the instructions in the readme but my page when it loads does the same query as the ssr page. However there is the NEXT_DATA with the right data. My cache is not hydrated, is it possible to have the source code of the demo so that I understand what I did wrong?

also:

In a page contained by WithApollo

export default WithApollo( { ssr : true } )( Home );

I have as props:

(2) [{…}, {…}]
0: {apolloState: {…}, apolloClient: null}
1: {}

The apolloState has the right data, how can I pass them to Apollo client ?

Thanks! 😃.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

0reactions
aboveyunhaicommented, Dec 30, 2020

@adrienpsl just want to further enhance your implementation in case if you hadn’t meet the problem. if (globalApolloClient && initialState && !hasSetInitialStore) will be executed when initalState = {} because if ({}) is evaluated true but we don’t want to restore the empty state obviously. So the true implementation is to do a true check on empty object such as

if (globalApolloClient && !isObjectEmpty(initialState) && !hasSetInitialStore)

export function isObjectEmpty(obj: Object) {
    for(var i in obj) return false;
    return true;
}

It seems like the problem only occurs on the really first render and and then you switch pages from SSR -> SSR -> go back to previous page SSR. The empty state kicks in and cause the unwanted store. SSR to CSR back and forth wouldn’t create that empty state; And it only appears on the first time.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Debugging and fixing hydration issues - somewhat abstract
As you may recall, for hydration to work properly, the initial render cycle of our React app on both the server and client...
Read more >
Avoiding hydration mismatch when using React hooks
A React hook or component MUST NOT return or render different values on the server and during the first render pass in the...
Read more >
Bug: Incorrect Hydration Mismatch Detection during Suspense ...
Bug : Incorrect Hydration Mismatch Detection during Suspense - "Hydration failed because the initial UI does not match what was rendered on the...
Read more >
React Pre-rendering and Potential Hydration Issue
hydrate() explains the cause of my issue: React expects that the rendered content is identical between the server and the client. It can...
Read more >
react-hydration-error - Next.js
While rendering your application, there was a difference between the React tree that was pre-rendered (SSR/SSG) and the React tree that rendered during...
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