Skip to content

Commit ba26083

Browse files
author
AGI Developer
committed
fix(i18n): add i18n.language to translate callback deps
1 parent 71db2e6 commit ba26083

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

webview-ui/src/i18n/TranslationContext.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,20 @@ export const TranslationProvider: React.FC<{ children: ReactNode }> = ({ childre
3333
}, [i18n, extensionState.language])
3434

3535
// Memoize the translation function to prevent unnecessary re-renders
36+
// Note: i18n.language must be included as a dependency so that the
37+
// translate function is recreated when the language changes. Without
38+
// this, React Compiler / React.memo consumers will cache stale
39+
// translations because the i18n object reference never changes.
40+
/* eslint-disable react-hooks/exhaustive-deps */
41+
// i18n.language must be included: i18n is a singleton whose reference
42+
// never changes, but language changes via changeLanguage()
3643
const translate = useCallback(
3744
(key: string, options?: Record<string, any>) => {
3845
return i18n.t(key, options)
3946
},
40-
[i18n],
47+
[i18n, i18n.language],
4148
)
49+
/* eslint-enable react-hooks/exhaustive-deps */
4250

4351
return (
4452
<TranslationContext.Provider

0 commit comments

Comments
 (0)