-
-
Notifications
You must be signed in to change notification settings - Fork 265
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
SSR Auth, fetching and setting auth user to the state inside App.getInitialProps causes an error when navigating between pages: Warning: Cannot update a component X while rendering a different component (App
).
#522
Comments
Header
) while rendering a different component (App
).App
).
App
).App
).
Will be fixed in #523 but will require some code changes. |
I am having same issue but this happens when I run the query in getServerSideProps and then call the rtkQuery hook inside any component or page, then I get the above error. But it appears just once and no more. |
Plus I am trying to achieve this but it doesn't work, because I need the context in the axiosbaseQuery I created and calling the endpoint in the getInitialProps of the app is out of the provider |
Just chiming in that this issue seems to occur when using RTK's dispatcher within a NextJS SSR block. I have a simple app skeleton that I am building out. It is using the SSR block to set the nav links into the state depending on the URL parameters. There is nowhere in the app's components where the store is changed other than with an When I transition from the first page to the next this warning appears. The only way I can make it go away is by removing any references to the state selector for example, the Example SSR Block:
The NavDrawer component (has the dispatch):
The NavLinks component (If I remove the selector from here the warning goes away):
This has been doing my head in for a few days now, any advice? |
Ok, so I have managed to find a solution in my specific situation. I think this is something which will be fixed in #523 if I read both the issue and the solution properly. In my case it seemed to be the case that the This meant that the From what I am making of it, the issue was: Initial state ( For me to solve this I altered my If anyone else has a better idea of why this approach worked I would definitely love to hear :) EDIT: Adding on to this it seems that allowing the
EDIT 2: The solution above is not a solution (whoops) turns out that by not including the links in the hydration update the menu is not updated when it should be and the first set of links the user acquires is the only one they will ever see :/ EDIT 3: Sorry for all the spam. Just want to chime in that upgrading to the latest pre release branch has removed the issue for me while allowing the nav links to be updated on the hydration action |
When I implemented the logic of fetching the authenticated user and setting it to the Redux state inside the
App.getInitialProps
method and accessing that user from the state within any Next.js page, I encountered an error when navigating between pages.Here is the problem. Inside
App.getInitialProps
I'm fetching the API endpoint using RTK Query to retrieve the auth user from the cookie and when the query is fulfilled user adds to the state. And that causes that error in the console.The query that I initiate inside App.getInitialProps:
The text was updated successfully, but these errors were encountered: