next-i18next: `appWithTranslations` HOC is not providing correct `I18nextProvider`
Describe the bug
While I navigate, the page don’t shows the translations but the keys.
Occurs in next-i18next version
8.8.0
, and next@10.0.1
Steps to reproduce
I have three pages and my setup is basically the same from this example:
_app.js
withexport default appWithTranslation(MyApp);
;- each page with its own exported
getServerSideProps
asasync ({ locale }) => ({ props: { ...await serverSideTranslations(locale, ['common', 'PAGE_NAME']) } })
Expected behaviour
The pages should load the namespaces and show translations.
OS
- OS: Ubuntu 20.04
- Browser: Chrome 92.0.4515.159 (Official Build) (64-bit)
Additional context
I added the I18nextProvider
to my tree and everything works:
import { useTranslation } from 'next-i18next';
import { I18nextProvider } from 'react-i18next';
const MyApp = ({ Component, pageProps }) => {
const { i18n } = useTranslation();
return (
<I18nextProvider i18n={i18n}>
<App />
</I18nextProvider>
);
};
export default appWithTranslation(MyApp);
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 5
- Comments: 26 (12 by maintainers)
Same here, thank god @basslagter that you suggested reverting to 8.7.0. I have spent 3 hours with this error:
@isaachinman No need for a reproducible example. Just create a plain next app (for me with typescript template) and it would not work.
@isaachinman it seems like this occurs (even in 10) when I add getInitialProps on a custom app in _app.js
When I skip
CustomApp.getInitialProps =
it seems to work. But I need this…Edit: Okay…it turns out I need to add getServerSideProps to every page to make this work…
@belgattitude Explicitly adding “i18next”: “20.6.1” didn’t change anything (according to yarn.lock I was anyhow on 20.6.1 for i18next)
@gabsprates few questions cause I’ve been affected (and downgraded to 8.7.0).
Do you import from react-i18next sometimes ? ie:
import { useTranslation } from 'react-i18next';
vsimport { useTranslation } from 'next-i18next
?Can you try with those locked deps:
PS: Asking that because I could partially reproduce when i18next version is > 20 here https://github.com/belgattitude/nextjs-monorepo-example/pull/510. I’ll probably need more time to have a full repro.