Skip to content

MBA-2266 (1/6): Node 20 + React 18, remove all 60 deprecated lifecycle calls - #8

Open
devin-ai-integration[bot] wants to merge 1 commit into
developfrom
devin/1788272519-mba-2266-react18-node20
Open

devin-ai-integration[bot] wants to merge 1 commit into
developfrom
devin/1788272519-mba-2266-react18-node20

Conversation

@devin-ai-integration

Copy link
Copy Markdown

✨ Description of Change

Link to GitHub issue or Jira ticket: MBA-2266

Description:

PR 1 of 6 of the src/js cleanup program. Scope is only the runtime/toolchain move to Node 20 + React 18 and the removal of the deprecated lifecycle calls. The duplicate-library convergence (react-table 6, react-final-form, moment, react-virtualized, font-awesome 4) is untouched here and lands in PRs 2-5.

Toolchain / deps

  • engines: Node ^14 → ^20, npm ^6 || ^7 → ^10.
  • react / react-dom 16.8.6 → 18.3.1, react-redux 7.1.3 → 8.1.3 (7.x does not support the React 18 renderer).
  • Test deps to their React 18 lines: @testing-library/react 12 → 14 (which absorbs renderHook, so @testing-library/react-hooks is dropped), react-test-renderer → 18.3.1, @types/react-dom → 18.3.7.

Root + imports

  • src/js/index.jsx: ReactDOM.render(<App/>, node) → createRoot(node).render(<App/>).
  • The three deep react-redux/es/... imports (index.jsx, MainRouter.jsx, put-away/SplitLineModal.jsx) → public { connect } / { Provider }. react-redux 8 ships no es/ entry points, so these were hard build breaks.
  • Deliberately not wrapping the tree in <StrictMode>. Double-invocation behavior is only meaningfully verifiable against a running app, which is PR 6's browser session; enabling it blind here would be an unverified claim.

The 60 deprecated lifecycle calls

All 60 componentWillReceiveProps methods are gone — rewritten, not renamed to UNSAFE_. grep -rn "componentWillReceiveProps\|componentWillMount\|componentWillUpdate\|UNSAFE_" src/js now returns nothing.

Two recipes were applied. Side-effecting bodies (the large majority — locale-change refetches, dataFetched one-shot guards, location-change refetches) became componentDidUpdate(prevProps) with the props references inverted:

-componentWillReceiveProps(nextProps) {
-  if (this.props.locale && this.props.locale !== nextProps.locale) {
-    this.props.fetchTranslations(nextProps.locale, 'stockMovement');
+componentDidUpdate(prevProps) {
+  if (prevProps.locale && prevProps.locale !== this.props.locale) {
+    this.props.fetchTranslations(this.props.locale, 'stockMovement');

Note that the inner guard becomes prevProps — it asks "did we already have a locale", not "do we have one now". Getting that backwards would turn "refetch on language switch" into "refetch on first locale arriving", so every guard was read individually rather than search-replaced.

Bodies that purely derive state from props (attr from fieldConfig + getDynamicAttr in the receiving/packing/substitution/adjust-inventory/edit-pick modals) became static getDerivedStateFromProps(props), which has no unconditional-setState hazard.

Where a body setStated unconditionally and could not be pure derivation (put-away/PutAwayCheckPage, put-away/PutAwaySecondPage), an explicit _.isEqual change guard was added — an unconditional setState inside componentDidUpdate is an infinite render loop, unlike inside componentWillReceiveProps. stock-list-management/StocklistManagement already had a componentDidUpdate; the converted logic was merged into it rather than declared twice.

Class components were left as classes; no conversions to function components.

React 18 behavior fixes

Three genuine React 18 breakages, not API renames:

  • Filter/FilterForm — countFilled setState'd during render (legal-ish in 16, an update loop in 18). It is now a pure function and amountFilled is a local const in the render callback.
  • GlobalSearch + Layout/NavbarIcons — renderButton called setIsTooltipDisabled during render. Visibility is now published through an onVisibilityChange prop fired from a useEffect.
  • receiving/ReceivingCheckScreen — under 18's automatic batching the spinner outlived the data load; hideSpinner() now runs in the setState callback.

Tests

  • The 7 src/js/tests/hooks/* files import renderHook/act from @testing-library/react.
  • Snapshots regenerated; every change is React 18 renderer formatting (<div></div> → <div />, one trailing blank line), no behavioral output change.
  • New regression suites for the three riskiest rewrites, chosen because they are the ones where a guard inverted: MainRouter (language switch refetches translations + menu config, and the first locale arriving does not), Layout/VerticalTabs (activeTab resets when the tab set size changes), receiving/modals/EditLineModal (attr derivation).

Bundle size (sum of emitted .js + .css, source maps excluded)

bytes
develop @ 4b703b8 8,149,672
this branch 8,207,161
+57,489 (+0.71%)

React 18's runtime is larger than 16.8's; this PR adds a library rather than removing one. The reductions in the ticket come from PRs 2-5, which delete one half of each duplicated library pair.

Devin-Org: engineering

Link to Devin session: https://app.devin.ai/sessions/c12d7fc2c18d47b3ad290cb76769412f
Open in Devin Desktop: https://app.devin.ai/desktop/session/c12d7fc2c18d47b3ad290cb76769412f?variant=devin

@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants