Skip to content

NXT-13028: Converted i18n/Text to functional component and fixed some root causes of unit tests console.error#3435

Merged
dan-ichim-lgp merged 2 commits into
developfrom
feature/NXT-13028
Jun 24, 2026
Merged

NXT-13028: Converted i18n/Text to functional component and fixed some root causes of unit tests console.error#3435
dan-ichim-lgp merged 2 commits into
developfrom
feature/NXT-13028

Conversation

@daniel-stoian-lgp

@daniel-stoian-lgp daniel-stoian-lgp commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Checklist

  • I have read and understand the contribution guide
  • A CHANGELOG entry is included
  • At least one test case is included for this feature or bug fix
  • Documentation was added or is not needed
  • This is an API breaking change

Issue Resolved / Feature Added

  1. There were console.error while running unit tests, althought the tests did pass
  2. Text component is class component. Need to modernize it

Resolution

Text.js:

  • class extends Component → function Decorator(props).
  • constructor + this.state.map → useState(() => getTextMap(...)) with a lazy initializer (map is still derived once from initial props, then only updated with translations — same as before).
  • componentDidMount + componentDidUpdate (translate on mount / on locale change) -> a single useEffect keyed on [locale, shouldTranslate].
  • checkPropTypes(this, ...) -> checkPropTypes(Decorator, ...) per render
  • Instance methods shouldTranslate/canRender/getTextForProp/translate -> migrated to local consts or inline logic in the render body.
  • setState({map}) -> functional setMap(prev => …), so the effect doesn't need map in its deps (which would otherwise loop).

i18n.js: Fixed the root cause of console.error in the unit tests "Cannot update a component (I18nDecorator) while rendering a different component (I18nDecorator). To locate the bad setState() call inside I18nDecorator, follow the stack trace as described in "

  • The warning was a real render-purity bug. useI18n calls setContext(locale) during render; in sync mode that synchronously ran loadResources --> _updateSnapshot --> _notifyListeners(), firing the useSyncExternalStore subscriber and scheduling a React update mid-render. Async mode already dodged this because _ready starts false.
  • The fix gives sync mode the same suppression, scoped precisely to the render-phase path:
    - Added this._updatingFromRender = false to the constructor.
    - setContext now sets that flag (in a try/finally) around its loadResources call.
    - _updateSnapshot only notifies when this._ready && !this._updatingFromRender.

use18n-specs.js :
a) Merge two unit test, because, the first one drives the I18n store directly: subscribe a listener, then call setContext('ar-SA') (the render-phase path useI18n triggers), and assert the listener is not notified while the snapshot is updated (getSnapshot().locale === 'ar-SA').
b) Added test for the scenario covered in i18n.js

Additional Considerations

Links

NXT-13028

Comments

Enact-DCO-1.0-Signed-off-by: Daniel Stoian (daniel.stoian@lgepartner.com)

@codecov

codecov Bot commented Jun 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.45%. Comparing base (99aa61a) to head (2d3555c).
⚠️ Report is 2 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3435      +/-   ##
===========================================
+ Coverage    86.28%   86.45%   +0.17%     
===========================================
  Files          156      156              
  Lines         7617     7765     +148     
  Branches      2017     2080      +63     
===========================================
+ Hits          6572     6713     +141     
- Misses         834      840       +6     
- Partials       211      212       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@daniel-stoian-lgp daniel-stoian-lgp changed the title NXT-13028: Converted i18n/Text cu functional component and fixed some root cause of unit tests console.error NXT-13028: Converted i18n/Text to functional component and fixed some root cause of unit tests console.error Jun 23, 2026
@daniel-stoian-lgp daniel-stoian-lgp changed the title NXT-13028: Converted i18n/Text to functional component and fixed some root cause of unit tests console.error NXT-13028: Converted i18n/Text to functional component and fixed some root causes of unit tests console.error Jun 23, 2026
@dan-ichim-lgp dan-ichim-lgp merged commit 69838e1 into develop Jun 24, 2026
10 checks passed
@dan-ichim-lgp dan-ichim-lgp deleted the feature/NXT-13028 branch June 24, 2026 12:44
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