Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable support for React 18 #763

Merged
merged 2 commits into from
Feb 20, 2025

Conversation

adamstankiewicz
Copy link
Member

@adamstankiewicz adamstankiewicz commented Feb 11, 2025

Description:

Related PRs:

The Open edX MFEs are overdue to support React 18 (especially as React 19 is already out now, too). Some efforts have been started to support React 18 in the shared JavaScript libraries, such as Paragon (openedx/paragon#3367, v22 and v23).

By enabling support for React 18 (should be additive-only), we can further enable incremental migration to React 18 within MFEs. Most of the changes are within the example MFE included in this repository for testing.

The React 18 Upgrade Guide was followed.

Merge checklist:

  • Consider running your code modifications in the included example app within frontend-platform. This can be done by running npm start and opening http://localhost:8080.
  • Consider testing your code modifications in another local micro-frontend using local aliases configured via the module.config.js file in frontend-build.
  • Verify your commit title/body conforms to the conventional commits format (e.g., fix, feat) and is appropriate for your code change. Consider whether your code is a breaking change, and modify your commit accordingly.

Post merge:

  • After the build finishes for the merged commit, verify the new release has been pushed to NPM.

@adamstankiewicz adamstankiewicz marked this pull request as draft February 11, 2025 19:47
@adamstankiewicz adamstankiewicz changed the title feat: support React 18 Enable support for React 18 Feb 11, 2025
"@openedx/frontend-build": "14.2.2",
"@openedx/paragon": "22.13.0",
"@openedx/frontend-build": "github:adamstankiewicz/frontend-build#ags/react-18",
"@openedx/paragon": "22.15.1",
Copy link
Member Author

@adamstankiewicz adamstankiewicz Feb 11, 2025

Choose a reason for hiding this comment

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

[inform] Paragon v22 supports React 18! 🎉

Copy link

codecov bot commented Feb 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.41%. Comparing base (b0774f2) to head (572702a).
Report is 5 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #763   +/-   ##
=======================================
  Coverage   83.41%   83.41%           
=======================================
  Files          40       40           
  Lines        1073     1073           
  Branches      197      197           
=======================================
  Hits          895      895           
  Misses        166      166           
  Partials       12       12           

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

@adamstankiewicz adamstankiewicz force-pushed the ags/react-18 branch 4 times, most recently from cb4a241 to 8a7ad83 Compare February 11, 2025 20:56
@adamstankiewicz adamstankiewicz marked this pull request as ready for review February 18, 2025 15:24
Comment on lines +4 to +6
const DynamicProvider = lazy(() => import('react-redux')
.then((module) => ({ default: module.Provider }))
.catch(() => ({ default: ({ children }) => children })));

Choose a reason for hiding this comment

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

this is the only part that's making me do a Tim Allen's hruuuh?? 😅

I guess to test my understanding, the OptionalReduxProvider needs to be synchronous with the fetching of a Redux Provider, because react-redux is now explicitly optional in the package.json?

Copy link
Member Author

@adamstankiewicz adamstankiewicz Feb 18, 2025

Choose a reason for hiding this comment

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

Before, OptionalReduxProvider assumes react-redux existed, and could be imported statically. With redux and react-redux now marked as optional peer dependencies, the import for react-redux is done at time of render instead of at build.

Now, once OptionalReduxProvider renders, React.lazy will suspend the component (rendering the below Suspense fallback) until the promise resolves. If the module import was successful, React.lazy resolves to the Provider component; otherwise, if the module doesn't exist, the error gets caught within React.lazy whereby the Provider component becomes largely a no-op component that simply renders its children.

Choose a reason for hiding this comment

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

Well put, totally makes sense, thanks! I'll be aiming to test this PR (and frontend-build's) this week!

Copy link
Contributor

@brian-smith-tcril brian-smith-tcril left a comment

Choose a reason for hiding this comment

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

LGTM!

I'm currently waiting on a PR sandbox deploy for openedx/frontend-app-authoring#1675. Once that is up and I've done some testing I'll approve openedx/frontend-build#625. Once that lands and this is updated to use the published version of frontend-build I'll approve this one!

@@ -56,7 +56,7 @@
"@cospired/i18n-iso-languages": "4.2.0",
"@formatjs/intl-pluralrules": "4.3.3",
"@formatjs/intl-relativetimeformat": "10.0.1",
"axios": "1.6.7",
"axios": "1.7.9",
Copy link
Member Author

Choose a reason for hiding this comment

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

[inform] resolves a security vulnerability

Copy link
Contributor

@brian-smith-tcril brian-smith-tcril left a comment

Choose a reason for hiding this comment

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

:shipit:

@brian-smith-tcril brian-smith-tcril merged commit 409c886 into openedx:master Feb 20, 2025
6 checks passed
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