Skip to content

Make react and lingui eager module-federation singletons to stabilize the federated i18n context#914

Open
raix wants to merge 1 commit into
platformplatform:mainfrom
raix:fix-federated-i18n-eager-singletons
Open

Make react and lingui eager module-federation singletons to stabilize the federated i18n context#914
raix wants to merge 1 commit into
platformplatform:mainfrom
raix:fix-federated-i18n-eager-singletons

Conversation

@raix

@raix raix commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Summary & Motivation

Make the federated translation context a single instance so a federated component's useLingui can no longer throw used without I18nProvider on a direct or reloaded page load.

  • Root cause, detected empirically: despite singleton: true, @lingui/core and @lingui/react were duplicated at runtime — a probe recorded two distinct i18n/LinguiContext/useLingui instances across the remote loads. A remote consumed early on a direct load (account's AuthSyncModal via the withSystemTranslations gate) fell back to its own bundled copy, getting a second LinguiContext with no provider. react/react-dom were not duplicated (pluginReact handles those), which is why only the Lingui path broke.
  • The change marks react, react-dom, @lingui/core, and @lingui/react as eager singletons in the module-federation shared map (in ModuleFederationPlugin.ts). eager places them in the shared scope during the host's synchronous startup, before any remote consumes them, so there is no per-remote fallback copy. The four are required together — eager Lingui synchronously requires react, so react/react-dom must be eager too. @tanstack/react-router and @tanstack/react-query stay non-eager singletons.

Checklist

  • I have added tests, or done manual regression tests
  • I have updated the documentation, if necessary

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

Successfully merging this pull request may close these issues.

1 participant