kirill-konshin / next-redux-wrapper

Redux wrapper for Next.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Data from store is undefined after client-side routing transition

kaguya3222 opened this issue · comments

Describe the bug

I use Next.js, rtk-query and next-redux-wrapper. I use getServerSideProps to set the initial state for the store on server and give a user a pre-rendered html page. So I expect that data from store will be immediately accessible on client, because it's set on the server. But when I'm using 8.0.0 version of next-redux-wrapper, after setting initial state on server the data is undefined on client after client-side routing transition for first several ticks of rendering. So I can't immediately use initial state of store on client, because store doesn't have initial state from server.

To Reproduce

Steps to reproduce the behavior:

  1. Go to this codesandbox
  2. Click on 'Go to pokemon' link
  3. See error

Expected behavior

The pokemon name is shown because store state should be set on the server and be immediately accessible on client.

Desktop (please complete the following information):

  • OS: Ubuntu 20.04
  • Google Chrome
  • Version 106.0.5249.103

Additional context

Everything works if I use next-redux-wrapper 7.0.5 version. The logic of 'setting initial state of store on the server' is located in pages/[pokemon].tsx file

@kirill-konshin Changed it to the suggested code, but it doesn't help: link

I'm looking into it further. Stay tuned.

https://github.com/kirill-konshin/next-redux-wrapper/releases/tag/8.1.0

Client hydration stopped working for me after updating to 8.1.0: store stays undefined indefinitely.
Hydration event is not fired on the client at all 🤔

The exact page uses incremental regeneration with getStaticPaths<{ fallback: true, paths: [] }> and getStaticProps fetching markdown from cms.

It worked okay'ish on 8.0.0: client wasn't hydrating on initial render, but at least hydration did push its state after awhile. Now on 8.1.0 it's complete silence.

@kaguya3222 what's your experience with this update, did it fix your issue?

@MrNovado To be honest, I haven't updated yet. Will check in the next days and provide feedback :)

@kirill-konshin I've just checked the same repro using 8.1.0 version and the bug if fixed, thank you !

@MrNovado For me it fixed my issue, however, I was testing with getServerSideProps. I didn't experience with getStaticProps since I don't have any cases