Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data from store is undefined after client-side routing transition #495

Closed
kaguya3222 opened this issue Oct 27, 2022 · 6 comments
Closed
Labels

Comments

@kaguya3222
Copy link

kaguya3222 commented Oct 27, 2022

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

@kaguya3222

This comment was marked as outdated.

@kirill-konshin kirill-konshin reopened this Nov 1, 2022
@kirill-konshin
Copy link
Owner

I'm looking into it further. Stay tuned.

kirill-konshin added a commit that referenced this issue Nov 1, 2022
kirill-konshin added a commit that referenced this issue Dec 28, 2022
* Use useMemo for hydration and avoid unnecessary hydrates (#502)

* Upgrade packages and refactor a bit
* Added necessary testing dependency
* Stop hydrating on server and use useLayoutEffect for client hydration
* Added pokemon page with rtk's createApi
* Added back dispatch in GSP in demo repo
* A change in query params constitutes a new page now
* Improve performance by using another hook on server
* Add detail page
* New approach: split gsp and gssp and hydrate based on those
* Added a second type of initial state handling with more explanations
* Improved useMemo comment
* Make sure hydrates work when staying on the same page
* Add links to demo repo to test issue (seems like no issue)
* Proper gipp fix (#512)
* ESLint fix
* Gipp testcase and example page in RTK repo (#514)
* Add GIP to _app and add GIP in page to RTK repo
* Added e2e test for RTK repo
* Added testcase for GIAP and GIPP to wrapper
* Consistent casing and formatting in comments

Fix #493 #495 #496

Co-authored-by: voinik <victor_panteleev@hotmail.com>
@kirill-konshin
Copy link
Owner

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

@MrNovado
Copy link

MrNovado commented Jan 17, 2023

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?

@kaguya3222
Copy link
Author

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

@kaguya3222
Copy link
Author

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants