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

useSuspense causes infinite rerender loop in NextJS app #1833

Open
artuska opened this issue Feb 14, 2025 · 4 comments
Open

useSuspense causes infinite rerender loop in NextJS app #1833

artuska opened this issue Feb 14, 2025 · 4 comments

Comments

@artuska
Copy link

artuska commented Feb 14, 2025

🐛 Bug Report

Setting react.useSuspense: true in i18next init options causes infinite interface rerenders when using useTranslation hook.

To Reproduce

Just set useSuspense to true.

const i18nextOptions: InitOptions = {
  debug: false,
  lng: "en",
  fallbackLng: "en",
  load: "currentOnly",
  preload: false,
  interpolation: {
    escapeValue: true,
  },
  react: {
    useSuspense: false, // default is `true` — https://github.com/i18next/next-i18next/issues/2095
  },
};

You can also enable debug with debug: true and see in the console infinite localeChanged events.

Expected behavior

No infinite rerender loop.

Your Environment

  • node 20.18.0, npm 10.8.2
  • "react": "18.3.1"
  • "react-i18next": "15.4.0"
  • "next-i18next": "15.4.2"
  • "i18next": "23.16.8"
  • os: any os
@adrai
Copy link
Member

adrai commented Feb 14, 2025

Like said in this comment, you should not use suspense => i18next/next-i18next#2095 (comment)

And also stated in the readme: https://github.com/i18next/next-i18next?tab=readme-ov-file#asynchronous-i18next-backends

@adrai adrai closed this as completed Feb 14, 2025
@artuska
Copy link
Author

artuska commented Feb 14, 2025

If i don't use useSuspense: true then my translation keys are “blinking” — first my translation key appears for 0.1 second and then translation text appears.

@artuska
Copy link
Author

artuska commented Feb 14, 2025

If i don't use useSuspense: true then my translation keys are “blinking” — first my translation key appears for 0.1 second and then translation text appears.

Wrapped my page code in <Suspense> component.

@adrai
Copy link
Member

adrai commented Feb 14, 2025

You should not need to wrap your code with Suspense if you don't use suspense...
Please provide a minimal reproducible example repository that illustrates your issue.

@adrai adrai reopened this Feb 14, 2025
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