Skip to content

Inform useTranslation hook of replaced i18n instance #1272

@medihack

Description

@medihack

🐛 Bug Report

I use the I18nextProvider to distribute the i18n instance in a Blitz.js app with SSR. When switching the language I simply replace the i18n instance in the provider (this is also how next-i18next works). This works when recreating every component, but breaks when just rerendering every component. It is because t of useTranslation is cached.
This also breaks next-i18next when using shallow routing. And it is not only a problem with shallow routing, but also with persistent layouts as those components in the layout (like app bars) are also not translated correctly after a page change (and replacing the i18n instance).

To Reproduce

Replace the i18n instance of a I18nextProvider and just force a rerender of all components that use the useTranslation hook. I also demonstrated this with a little code change in the example app of next-i18next (https://github.com/medihack/next-i18next).

Expected behavior

The useTranslation hook should somehow check if its provided i18n instance was replaced and not just provide a cached t function.

Your Environment

  • runtime version: node v15.5
  • i18next version: 11.8.8
  • os: Windows WSL

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions