Skip to content

Fix React Compiler memoization error in I18nProvider#415

Merged
hotlong merged 2 commits intomainfrom
copilot/update-ci-pipeline-configuration
Feb 9, 2026
Merged

Fix React Compiler memoization error in I18nProvider#415
hotlong merged 2 commits intomainfrom
copilot/update-ci-pipeline-configuration

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 9, 2026

CI failing on eslint-plugin-react-hooks@7.0.1's preserve-manual-memoization rule. The rule enforces correct dependencies in useMemo hooks and cannot be suppressed with eslint-disable comments.

Changes

  • packages/i18n/src/provider.tsx: Added config to useMemo dependency array

The I18nProvider component was memoizing the i18n instance based only on externalInstance, ignoring config despite using it:

// Before: incorrect dependencies
const i18nInstance = useMemo(
  () => externalInstance || createI18n(config),
  [externalInstance], // eslint-disable-line react-hooks/exhaustive-deps
);

// After: correct dependencies
const i18nInstance = useMemo(
  () => externalInstance || createI18n(config),
  [externalInstance, config],
);

This ensures the i18n instance is recreated when config changes, and allows the React Compiler to optimize correctly.

Original prompt

引用: https://github.com/objectstack-ai/objectui/actions/runs/21827984712/job/62977961122#step:7:1


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@vercel
Copy link
Copy Markdown

vercel Bot commented Feb 9, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
objectui Ready Ready Preview, Comment Feb 9, 2026 3:28pm
objectui-console Ready Ready Preview, Comment Feb 9, 2026 3:28pm
objectui-storybook Ready Ready Preview, Comment Feb 9, 2026 3:28pm

Request Review

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Copilot AI changed the title [WIP] Update CI pipeline configuration settings Fix React Compiler memoization error in I18nProvider Feb 9, 2026
Copilot AI requested a review from hotlong February 9, 2026 14:50
@hotlong hotlong marked this pull request as ready for review February 9, 2026 14:58
Copilot AI review requested due to automatic review settings February 9, 2026 14:58
@hotlong hotlong merged commit f722abb into main Feb 9, 2026
1 of 4 checks passed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes CI failure from eslint-plugin-react-hooks@7.0.1 (react-hooks/preserve-manual-memoization) by correcting useMemo dependencies in I18nProvider, aligning memoization with the values used to create the i18n instance.

Changes:

  • Add config to the useMemo dependency array used to create/memoize the i18nInstance.
  • Remove the prior eslint-disable suppression for hook dependencies.

Comment on lines 43 to 47
export function I18nProvider({ config, instance: externalInstance, children }: I18nProviderProps) {
const i18nInstance = useMemo(
() => externalInstance || createI18n(config),
[externalInstance], // eslint-disable-line react-hooks/exhaustive-deps
[externalInstance, config],
);
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
const i18nInstance = useMemo(
() => externalInstance || createI18n(config),
[externalInstance], // eslint-disable-line react-hooks/exhaustive-deps
[externalInstance, config],
);
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.
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.

3 participants