-
Notifications
You must be signed in to change notification settings - Fork 2
Fix React Compiler memoization error in I18nProvider #415
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
44
to
47
|
||
|
|
||
| const [language, setLanguage] = useState(i18nInstance.language || 'en'); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With
configin the dependency array, any caller passing an inline object literal (e.g. the docs/examples useconfig={{ defaultLanguage: 'zh' }}) will cause this memo to invalidate on every render and repeatedly runcreateI18n(config)(which callsi18next.createInstance().init(...)). Consider documenting thatconfigmust be referentially stable (memoized) or restructuring the provider so it only recreates the instance when config values meaningfully change.