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

Warning: React has detected a change in the order of Hooks called by WrapRoot. #1

Closed
cryptolokimax opened this issue Sep 7, 2019 · 5 comments

Comments

@cryptolokimax
Copy link

Hello,

First of all, thank you for the plugin - it's exactly what I was looking for. However it seems to have a problem with rendering. Console displays the following error:

Warning: React has detected a change in the order of Hooks called by WrapRoot. This will lead to bugs and errors if not fixed. For more information, read the Rules of Hooks: https://fb.me/rules-of-hooks

   Previous render            Next render
   ------------------------------------------------------
1. useState                   useContext
   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    in WrapRoot (created by LocationProvider)
    in LocationProvider (created by Context.Consumer)
    in Location (created by WithLocationComponent)
    in WithLocationComponent
    in Suspense
    in _default (at app.js:67)

Which affects the build, I beleive, as after rendered page is loaded, it flickers to translation variables, which are replaced by translation in a fraction of a second.

Do you have any idea of what it can be?

@onestopjs
Copy link
Owner

onestopjs commented Sep 7, 2019

Hi!
First of all, thank you for the feedback!

About the order of hooks issue, I get the error too. However, I am not sure why that happens as all the hooks are rendered the same way each time, and I haven't used neither useState nor useContext in WrapRoot. This leads me to think that something is internally using those to cause the problem. I will look into it immediately! Thank you for reporting!

About the flicker problem, did you set useSuspense and wait options in i18next to true? Refer to the example config here. Does this solve at least the flicker issue for you?

@onestopjs
Copy link
Owner

I think I managed to pinpoint the problem - useTranslation from react-i18next calls useContext conditionally. I opened an issue and made a PR. As soon as it is fixed, I will update react-i18next in this plugin and the issue should be resolved! :)

You can track the issue here if you are interested.

@onestopjs
Copy link
Owner

Turns out there was also a goof up on my part. I fixed it and the issue should be gone now, but I will still update the package when/if my PR is merged.

Update to the latest version and tell me if the issue persists :)

@cryptolokimax
Copy link
Author

Thank you for fast response! Yes, the issue was fixed for me, thank you! Now it's officially the best and easiest localisation plugin for gatsby! :)

@onestopjs
Copy link
Owner

Thank you, I am glad you find it useful :)

I will be closing the issue now, if you have any other problems or feature suggestions, don't hesitate to open another issue!

onestopjs added a commit that referenced this issue Oct 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants