Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Jan 30, 2026

Related GitHub Issue

Closes: #11100

Description

This PR attempts to address Issue #11100. Feedback and guidance are welcome.

PR #9565 added React Compiler integration which automatically handles memoization in React applications. The issue is that the TranslationContext has a memoization bug that React Compiler exposes:

The translate callback in TranslationContext.tsx depends only on [i18n], but i18n is a singleton object whose reference never changes - only its internal language state changes when i18n.changeLanguage() is called. This means the translate callback was never recreated when the language changed, and React Compiler could aggressively cache the results of components using translations.

Fix: Added i18n.language to the dependency array of the useCallback hook. This ensures the translate function is recreated when the language changes, causing all components using useAppTranslation() to properly re-render with updated translations.

Test Procedure

  1. Existing tests for TranslationContext pass: cd webview-ui && npx vitest run src/i18n/__tests__/TranslationContext.spec.tsx
  2. Manual testing: Change the language in settings and verify that all internationalized text updates correctly throughout the UI

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes (if applicable).
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Documentation Updates

  • No documentation updates are required.

Additional Notes

The eslint-disable comment is intentional - the react-hooks/exhaustive-deps rule flags i18n.language as "unnecessary" because it is not used inside the callback body. However, this dependency is specifically needed to trigger re-memoization when the language changes, since i18n.t() internally depends on the current language setting.


Important

Fixes memoization bug in TranslationContext.tsx by adding i18n.language to useCallback dependencies, ensuring proper re-rendering on language change.

  • Behavior:
    • Fixes memoization bug in TranslationContext.tsx by adding i18n.language to useCallback dependencies.
    • Ensures translate function is recreated when language changes, preventing React Compiler from over-caching.
  • Testing:
    • Existing tests for TranslationContext pass.
    • Manual testing confirms UI updates correctly on language change.

This description was created by Ellipsis for ac046a4. You can customize this summary. It will automatically update as commits are pushed.

@roomote
Copy link
Contributor Author

roomote bot commented Jan 30, 2026

Rooviewer Clock   See task on Roo Cloud

Review complete. No issues found.

The fix correctly addresses the React Compiler memoization bug by adding i18n.language to the useCallback dependency array. The change is minimal, well-documented, and ensures proper re-rendering when language changes.

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

[BUG] React Compiler bug

1 participant