-
-
Notifications
You must be signed in to change notification settings - Fork 766
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
appWithTranslation is causing the React state to not consist when doing client-side page navigation. #2259
Comments
I also noticed that the issue is only happening when one page is translated and the other is not. |
That's exactly the problem... import nextI18nextConfig from '../../next-i18next.config';
//...
export default appWithTranslation(MyApp, nextI18nextConfig); |
Hi @adrai Thanks for the quick reply and the suggestion! To give you some context on my original issue which made create this example repo and this Github issue. I started to add next-i18next to a few page in an existing NextJs website that has a lot of pages. I am wondering if there is a way next-i18next can always make sure to wrap an app with the OR update the README/docs to mention the issue here and how to solve it? basically to make sure other people are not facing the same issue 😃 Maybe something like:Partially translated websiteOR Start using next-i18next IncrementallyIf you want to only use next-i18next on some pages make sure to do the following import nextI18nextConfig from '../../next-i18next.config';
//...
export default appWithTranslation(MyApp, nextI18nextConfig); |
Feel free to provide a PR to update the readme |
@adrai sure 😄 just confirm: you don't think it is feasible or good idea to always wrap the app with a Provider? and if no, why? 🙏 |
no, we tried this in the past, and it resulted in other errors |
Opened a PR |
* Init i18next * Remove unused file * Switch to next-i18next * Add configuration and translate cookie banner * Fix Next.js warning "API handler should not return a value, received object" * Translate footer and add eslint rule to avoid import mistake * Ensure SSR and CSR bundles provide consistent i18n config. See i18next/next-i18next#2259 for details * Remove unused page * Remove unused property * Add top-level translations for StartPage * No need for translations when redirecting * Add 404 translations * Simplify DropDown to remove unused classes * Fix formatting error in Header * Remove Footer tests since they 1) it wasn't worth adapting them to the new i18n structure, and 2) because they tested the content rather than cricital functionality * Combine footer and common translations into a single namespace * Fix formatting issue * Add basic i18n to remaining pages * Use markdown to simplify i18n for dataset definitions * Style Markdown content according to the theme, with the option to override components * Use markdown for `body` field of DataDescriptions * Simplify date formatting * Prevent styled-components from rendering invalid HTML props * Remove unused components * Add translations for common components * Fix layout issue * Begin adding municipality translations * Add translations for municipality numbers * Allow ScorecardSections to use consistent formattig even with markdown content * Add municipality ScoreCard translations * Use HTML details element to make ScorecardSection more accessible and easier to use * Styling tweaks * Add missing key attribute * Fix React hydration error caused by missing <thead> element * Add solutions translations * Improve styles for Markdown * Replace JSX with Markdown formatting * Use markdown formatting instead of JS override * Translate utsläppsberakningar and use Markdown for simplified formatting * Translate partierna, and update next/image props * Translate Källor och Metod * Improve grid styling on about page * Translate about page * Improve spacing * Clarify dataset task ideas * Translate sitemap * Update tests to use mocked i18n and test against expected keys rather than values * Begin translating datasets * Translate the easy parts of dataset definitions * Clarify naming * Replace deprecated method String#substr with String#slice * Refactor to prepare for translated dataDescriptions * Add translations for datasets * WIP: hack around broken SSR translations * Cleanup SSR translations * Separate hardcoded dataset keys from the UI labels, to allow translations * Update tests to reflect fully translated datasets * Reduce margin-top for FactSection * Fix translation error * Fit images in container width * Fix modal positioning. Also improve UX by closing on backdrop click. Long term our custom Modal should be replaced with a standard Modal solution. * Ensure special data for climate plans and procurements renders correctly. Also improve TypeScript types to prevent this error in the future. * Fix type error * Revert spacing change for CementClarification
🐛 Bug Report
Wrapper _.app.js with the
appWithTranslation
HOC is causing the React state to not consist when doing client-side page navigation.To Reproduce
I created this repo with a simple example that you can clone and try:
https://github.com/pgburrack/next-i18next-issue
In the example repo I created a DummyProvider with the initial state.
Steps to reproduce:
npm run dev
+ open http://localhost:3000/console
developer tools. I would expect to see:👆 this is the state that is in the
DummyProvider
.3. Click on "Go to about page" (while keeping the console open)
You will see that the state in DummyProiver is initiated again.
Note: if you comment out
appWithTranslation
and just export the App component.you will see that the state is being kept on client-side navigation.
Expected behavior
When navigating to the /about page i would expect the DummayProvider to be
Your Environment
P.S i found that if I pass options to
appWithTranslation
it will work as expected.Example:
The docs are not saying to do that as well, as we have that information in
next-i18next.config.js
so i am not sure why i would need to do that.I suspect that the following line of code is causing the issue
https://github.com/i18next/next-i18next/blob/master/src/appWithTranslation.tsx#L120
I saw that when doing the navigation will disappear.
Could use help with this 🙏
The text was updated successfully, but these errors were encountered: