Skip to content

feat: upgrade react to v18 #1220

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

Merged
merged 3 commits into from
Apr 4, 2025
Merged

Conversation

huniafatima-99
Copy link
Contributor

@huniafatima-99 huniafatima-99 commented Mar 26, 2025

Description

This PR upgrades react to v18. It also updated the test cases to remove the deprecated approaches according to react 18.

How Has This Been Tested?

All the test suites were ran and they were successful. In addition, major functionalities are working when ran the MFE in the browser.

Merge Checklist

  • If your update includes visual changes, have they been reviewed by a designer? Send them a link to the Sandbox, if applicable.
  • Is there adequate test coverage for your changes?

Post-merge Checklist

  • Deploy the changes to prod after verifying on stage or ask @openedx/edx-infinity to do it.
  • 🎉 🙌 Celebrate! Thanks for your contribution.

Copy link

codecov bot commented Mar 26, 2025

Codecov Report

Attention: Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.

Project coverage is 58.50%. Comparing base (17e12f7) to head (b71f55a).
Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
src/index.jsx 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1220      +/-   ##
==========================================
- Coverage   58.53%   58.50%   -0.03%     
==========================================
  Files         117      117              
  Lines        2320     2321       +1     
  Branches      639      641       +2     
==========================================
  Hits         1358     1358              
- Misses        901      902       +1     
  Partials       61       61              

☔ View full report in Codecov by Sentry.
📢 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.

@huniafatima-99 huniafatima-99 linked an issue Mar 26, 2025 that may be closed by this pull request
@huniafatima-99 huniafatima-99 self-assigned this Mar 26, 2025
@huniafatima-99 huniafatima-99 force-pushed the hunia/react-v18-upgrade branch from 6867a1f to 9134eea Compare March 26, 2025 09:01
@brian-smith-tcril
Copy link
Contributor

Thank you so much for opening this PR! The plan for the React 18 upgrades is to use StrictMode - would you be able to update this PR to do that?

https://react.dev/reference/react/StrictMode

@huniafatima-99
Copy link
Contributor Author

@brian-smith-tcril sure, let me update the PR.

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.

Thank you so much for this! Overall it's looking great. Just one small note about a snapshot test that seems to have broken.

/>,
]
`;
exports[`SuccessModal should match open success modal snapshot 1`] = `undefined`;
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like something broke this snapshot.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@brian-smith-tcril resolved.

@huniafatima-99 huniafatima-99 force-pushed the hunia/react-v18-upgrade branch from 0c2a585 to b05dc8f Compare April 3, 2025 12:59
/>,
]
`;
exports[` 1`] = `undefined`;
Copy link
Contributor

Choose a reason for hiding this comment

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

@huniafatima-99 it looks like this changed but now instead of replacing the actual snapshot with

exports[`SuccessModal should match open success modal snapshot 1`] = `undefined`;

it doesn't even say "SuccessModal should match open success modal snapshot" anymore

Copy link
Contributor

Choose a reason for hiding this comment

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

I did a bit of digging into this. If you replace SuccessModal.test.jsx with

import React from 'react';
import renderer from 'react-test-renderer';
import { IntlProvider, injectIntl } from '@edx/frontend-platform/i18n';

import { waitFor } from '@testing-library/react';
import { SuccessModal } from './SuccessModal'; // eslint-disable-line import/first

// Modal creates a portal.  Overriding createPortal allows portals to be tested in jest.
jest.mock('react-dom', () => ({
  ...jest.requireActual('react-dom'),
  createPortal: jest.fn(node => node), // Mock portal behavior
}));

const IntlSuccessModal = injectIntl(SuccessModal);

describe('SuccessModal', () => {
  let props = {};

  beforeEach(() => {
    props = {
      onClose: jest.fn(),
      status: null,
    };
  });

  it('should match default closed success modal snapshot', async () => {
    await waitFor(() => {
      const tree = renderer.create((
        <IntlProvider locale="en"><IntlSuccessModal {...props} /></IntlProvider>))
        .toJSON();
      expect(tree).toMatchSnapshot();
    });

    await waitFor(() => {
      const tree = renderer.create((
        <IntlProvider locale="en"><IntlSuccessModal {...props} status="confirming" /></IntlProvider>))
        .toJSON();
      expect(tree).toMatchSnapshot();
    });

    await waitFor(() => {
      const tree = renderer.create((
        <IntlProvider locale="en"><IntlSuccessModal {...props} status="pending" /></IntlProvider>))
        .toJSON();
      expect(tree).toMatchSnapshot();
    });

    await waitFor(() => {
      const tree = renderer.create((
        <IntlProvider locale="en"><IntlSuccessModal {...props} status="failed" /></IntlProvider>))
        .toJSON();
      expect(tree).toMatchSnapshot();
    });
  });

  it('should match open success modal snapshot', async () => {
    await waitFor(() => {
      const tree = renderer
        .create((
          <IntlProvider locale="en">
            <IntlSuccessModal
              {...props}
              status="deleted"
            />
          </IntlProvider>
        ))
        .toJSON();
      expect(tree).toMatchSnapshot();
    });
  });
});

it will match the snapshots as they are currently saved on master.

It does feel a bit odd that we have a bunch of snapshots specifically looking for null - but I consider cleaning that up as out of scope for this PR. I looked through the history and found those changed in #654, so continuing to check for null snapshots in this PR is fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@brian-smith-tcril You are right, waiting for react and document to be ready before taking the snapshot did the magic. Thank you for the solution. Much appreciated.

@huniafatima-99 huniafatima-99 marked this pull request as draft April 3, 2025 17:53
@brian-smith-tcril brian-smith-tcril added the create-sandbox open-craft-grove should create a sandbox environment from this PR label Apr 4, 2025
@huniafatima-99 huniafatima-99 marked this pull request as ready for review April 4, 2025 08:34
@open-craft-grove
Copy link

Sandbox deployment failed 💥
Please check the settings and requirements.
Retry deployment by pushing a new commit or updating the requirements/settings in the pull request's description.
📜 Failure Logs
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@open-craft-grove
Copy link

Sandbox deployment successful 🚀
🎓 LMS
📝 Studio
ℹ️ Grove Config, Tutor Config, Tutor Requirements

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!

Note

The codecov difference is just because index.jsx is not covered by any tests in this repo. I consider it non-blocking.

@brian-smith-tcril brian-smith-tcril merged commit 515890d into master Apr 4, 2025
6 of 8 checks passed
@brian-smith-tcril brian-smith-tcril deleted the hunia/react-v18-upgrade branch April 4, 2025 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
create-sandbox open-craft-grove should create a sandbox environment from this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

React 18 Upgrade
3 participants