Problem with loading behaviour when doing SSR and PersistGate

See original GitHub issue

Hey guys,

Great solve for the persistence problem, although I have an issue.

<PersistGate loading="loading" persistor={persistor}>

    <MyEntireApp />

</PersistGate/>

When the app is rendered from the server, the react component tree is already created and the view is already rendered, but because of <PersistGate /> the whole tree is reconstructed as it has to render the loading text instead of the whole app while persist is syncing with the store and then again construct the whole app’s component tree, which leads to a break in user experience.

Imagine this - Web app Rendered (from server) -> Loading Text Rendered (when client JS comes into play and persistor starts hydrating) -> Web app Re-rendered (after persistor is done hydrating the store)

A not so user friendly experience.

Basically this line in PersistGate creates problem when doing SSR - this.state.bootstrapped ? this.props.children : this.props.loading

react v16 redux-persist v5.7.0

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:5
  • Comments:8

github_iconTop GitHub Comments

13reactions
rajatbarmancommented, Mar 18, 2019

To those looking for solution. Don’t use <PersistGate /> wrapper, instead wrap this logic over ReactDOM.hydrate

persistor.subscribe(() => {
          /* Hydrate React components when persistor has synced with redux store */
          const { bootstrapped } = persistor.getState();

          if (bootstrapped) {
              ReactDOM.hydrate(
                  <MyEntireApp />,
                  document.getElementById("appOrWhatever")
            );
          }
        });
2reactions
max8hinecommented, Jun 25, 2019

Having few issues with the SSR in Gatsby. Such as:

  1. could not load the persisted data correctly
  2. providing google/facebook crawling the Gatsby site Any solution or progress for it?
Read more comments on GitHub >

github_iconTop Results From Across the Web

NEXT.JS with persist redux showing unexpected behaviour
I have no idea how to fix this, as am new to NEXT.JS and REDUX. Please check the below video to get an...
Read more >
The Definitive Guide to Redux Persist - React Native Coach
Redux Persist takes your Redux state object and saves it to persisted storage. Then on app launch it retrieves this persisted state and...
Read more >
Using redux with redux-persist with server-side rendering ...
When you use Redux-persist with SSR, It creates crashes, problems like It shows you white screen for 1-5 seconds and then shows the...
Read more >
next-redux-cookie-wrapper - npm
Start using next-redux-cookie-wrapper in your project by running `npm ... Redux Persist offers a PersistGate React component for this which ...
Read more >
Redux Persist With Next.js - Lightrains
But when it comes to SSR (Server Side Rendering) React such as Next.js, ... import { PersistGate } from 'redux-persist/integration/react' ...
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