Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/i18n/src/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export interface I18nProviderProps {
export function I18nProvider({ config, instance: externalInstance, children }: I18nProviderProps) {
const i18nInstance = useMemo(
() => externalInstance || createI18n(config),
[externalInstance], // eslint-disable-line react-hooks/exhaustive-deps
[externalInstance, config],
);
Comment on lines 43 to 47
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With config in the dependency array, any caller passing an inline object literal (e.g. the docs/examples use config={{ defaultLanguage: 'zh' }}) will cause this memo to invalidate on every render and repeatedly run createI18n(config) (which calls i18next.createInstance().init(...)). Consider documenting that config must be referentially stable (memoized) or restructuring the provider so it only recreates the instance when config values meaningfully change.

Copilot uses AI. Check for mistakes.
Comment on lines 44 to 47
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that config can trigger a new i18nInstance, language state is still initialized only once from the initial instance. If config changes and a new instance is created, language/direction can become out of sync with the new instance until a languageChanged event fires (which may never happen). Consider syncing language when i18nInstance changes (e.g., set it to i18nInstance.language || 'en' on instance change).

Copilot uses AI. Check for mistakes.

const [language, setLanguage] = useState(i18nInstance.language || 'en');
Expand Down
Loading