-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Issue with React 16.13: Cannot update a component [ X] while rendering a different component [Y]. #1124
Comments
Looks like more related to your sample than to what react-i18next provides? |
If I remove In my component import React from 'react'
import LocaleContext from './locale-context'
import { useTranslation } from "react-i18next"
const LocaleProvider = ({ children, locale}) =>{
const { i18n } = useTranslation()
i18n.language !== locale && i18n.changeLanguage(locale);
return <LocaleContext.Provider value={locale}>{ children }</LocaleContext.Provider>
}
export default LocaleProvider |
Still, the problem does not exist in our samples...so it's specific to your setup, configuration... |
Ok. How can i identify where is the problem? Because I don't have idea what is it going on |
try:
|
@ifmael any luck? I am seeing this to, is to do with |
@CrashyBang Can you provide a reproducible sample on codesandbox - really would love to get this solved. |
@jamuhl I've tried everything that you told me but I get the same error. The error only shows the first time that I changed the language. All subsequent navigations work correctly |
Can't reproduce it on a non-gatsby sample - and won't invest hours to debug through the provided sample. |
Finally, I've solved my issue, but to be honest, I'm not pretty sure why the below code solves the problem: import React, { useEffect } from 'react'
import LocaleContext from './locale-context'
import { useTranslation } from "react-i18next"
const LocaleProvider = ({ children, locale}) =>{
const { i18n } = useTranslation()
useEffect( () =>{
i18n.language !== locale && i18n.changeLanguage(locale);
}, [locale]);
return <LocaleContext.Provider value={locale}>{ children }</LocaleContext.Provider>
}
export default LocaleProvider It's like |
changeLanguage has no side-effects (it's not even react-i18next) -> it sets language on the i18next instance and sends an event that is used in useTranslation to trigger a rerender I'm not even sure why you need a LocaleProvider...but anyway...if it works...it works |
Maybe I don't need it...it's the first time I'm working with i18n and language so I am a little confused. With this locale, I feed the |
All |
Nice!. Thanks! |
For my same case of problem, i was resolved it using
Thank! |
I got the same issue while doing some test with I fixed the issue by removing the line 88 of
If I well understand the flow, it's not mandatory. Indeed (with Btw I |
@rmedaer might indeed not be needed...honestly, I never tested if it works without that line...as of the time of writing that code Suspense was still rather new. If you like you can provide a PR removing that line... |
As documented in i18next#1124 (comment) this fix should avoid `setState` while react is rendering.
Hi there, You probably saw the fix and PR I did yesterday. I double checked and I can confirm it fix my issues (same setState-in-render error). Could you test the release 11.7.2 and confirm it works as well on your side ? @ifmael @an-parubets Kind regards, |
This change breaks with an error |
@hc-codersatlas could you give us a minimal piece of code which reproduce the issue. |
@hc-codersatlas any update on this...not sure how getting a |
Bumped the version number from 11.7.1 to 11.7.2 and it came up. Haven't been able to replicate it as a separate project yet. |
should be closed by #1165 |
Even with v11.7.2, still had to set I'm not sure what my next steps should be... |
@trumbitta a codesandbox with reproduction case might be a good first step |
still...this not yet happened ever to me...so how should I fix something that is not reproducible... |
@jamuhl I hear you, and I will do my best to come back with a reproduction... meanwhile, going further with my investigations, if I disable the localStorage backend then the warning goes away. Still not a feasible solution for my case, but at least I have one more clue for what to look for while I try to put a reproduction together. |
I'm also experiencing the same issue, with stacktrace also pointing to |
Update: I wasn't able to reproduce on codesandbox, but my tests on my own project all point to the localstorage backend. I fixed my issue by disabling suspense support and calling it a day. |
same for me. Playing around with suspense: false didnt change anything unfortunately. Understanding the code near the boundReset() is clearly not a no-brainer ;-) And when i see that the nextjs guys also hitting the problem with their impl, i think there is something there. They reported that using useTranslation() might be an issue but i use it all over the place and not i18n.t(). Since this is only a development mode issue with gatsby and not in the generated pages on prod, i dont know how much time i will give this topic. |
I still have this issue on Next.js 13 |
I also still have this issue, Next.js 14 |
🐛 Bug Report
React show a warning when a function component is updated during another component's render phase. https://fb.me/setstate-in-render
To Reproduce
The codesandbox to reproduce the issue:
Expected behavior
I don't expect to see a warning in the console
Your Environment
The text was updated successfully, but these errors were encountered: