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

Summary

Fixes partial internationalization failures caused by React Compiler aggressively caching translated values when the language changes.

Closes #11100

Changes

TranslationContext.tsx

  • Add i18n.language to the translate callback dependency array
  • This forces re-memoization when the language changes, ensuring React Compiler picks up the updated translations

ChatView.tsx

  • Store translation keys instead of translated values: Changed primaryButtonText/secondaryButtonText state variables to store translation keys (primaryButtonKey/secondaryButtonKey) instead of already-translated strings
  • Compute translations at render time: Added computed values that call t() with the stored keys during render, ensuring fresh translations
  • Pre-computed tooltip mappings: Created primaryButtonTooltipMap and secondaryButtonTooltipMap to map button keys to their tooltip keys, simplifying the render logic
  • Removed redundant type annotations: Removed explicit <boolean> type annotations from useState calls that React Compiler may have issues inferring

Root Cause

The React Compiler (babel-plugin-react-compiler) aggressively memoizes values. When button text was stored as already-translated values (e.g., setPrimaryButtonText(t("chat:retry.title"))), the translated value was cached in state. When the user changed language, the state value remained stale because React Compiler did not recognize that t() results depend on i18n.language.

Solution

By storing translation keys instead of values, we ensure that:

  1. The t() function is called fresh on every render
  2. The TranslationContext properly invalidates when language changes (via i18n.language dependency)
  3. React Compiler cannot incorrectly cache stale translated strings

Testing

  • TypeScript compiles without errors
  • ESLint passes
  • TranslationContext tests pass
  • App tests pass

Important

Fixes React Compiler i18n caching issues by updating translation handling in ChatView.tsx and TranslationContext.tsx.

  • Behavior:
    • Fixes i18n caching issues by ensuring translations update when language changes.
    • Stores translation keys in ChatView.tsx and computes translations at render time.
  • TranslationContext.tsx:
    • Adds i18n.language to translate callback dependencies to force re-memoization on language change.
  • ChatView.tsx:
    • Changes primaryButtonText/secondaryButtonText to store keys (primaryButtonKey/secondaryButtonKey).
    • Computes primaryButtonText/secondaryButtonText and tooltips at render time.
    • Removes redundant <boolean> type annotations from useState calls.

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

Fixes partial internationalization failures caused by React Compiler
aggressively caching translated values.

Changes:
- TranslationContext: Add i18n.language to translate callback dependency
  to force re-memoization when language changes
- ChatView: Store translation keys instead of translated button text
  in state, compute translations at render time
- ChatView: Remove redundant useState type annotations that may confuse
  React Compiler type inference
- ChatView: Simplify button tooltip rendering by using pre-computed
  tooltip values from key mappings

Closes #11100
@roomote roomote bot requested review from cte, jr and mrubens as code owners January 30, 2026 04:51
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Jan 30, 2026
@roomote roomote bot mentioned this pull request Jan 30, 2026
@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 i18n caching issue by:

  1. Adding i18n.language to the translate callback dependency array in TranslationContext
  2. Storing translation keys instead of translated values in ChatView state
  3. Computing translations at render time to ensure fresh values when language changes

All translation keys have been verified to exist in the locale files.

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

bug Something isn't working size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

[BUG] React Compiler bug

1 participant