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

Upgrade outdated packages; Bump React to v18 #7548

Merged
merged 32 commits into from
May 24, 2023

Conversation

thelovekesh
Copy link
Collaborator

@thelovekesh thelovekesh commented May 15, 2023

Summary

Previously we attempted to upgrade React in #7394 but due to React version inconsistencies on the upstream, we ended up blocking that PR.

This PR aims to upgrade React to v18 with the following enhancements:

  • Migrated JS(React) test cases to @testing-library/react.
  • Update the AfterActivationSiteScan service to work with React >= 18.
  • Migrated from deprecated registerStore in the @wordpress/data package.
  • Add jest resolver to fix failing tests due to the UUID package.
  • Updated tests container in wp-env commands.
  • Update workflow to run E2E tests with Node 16.

Checklist

  • My code is tested and passes existing tests.
  • My code follows the Engineering Guidelines (updates are often made to the guidelines, check it out periodically).

ampprojectbot and others added 22 commits May 16, 2023 03:03
- Remove unsage of `render` from `@wordpress/element`
- Use `act` from `@testing-library/react` instead of `react-dom/test-utils`

- Update test cases for AMPDocumentStatusNotification component
- Update test cases for AMPRevalidateNotification component
- Update test cases for AMPValidationStatusNotification component
- Update test cases for Icons component
- Update test cases for SidebarNotification component
- Update test cases for SidebarNotificationsContainer component
- Update test cases for withAMPToolbarButton component
- Update test cases for useAMPDocumentToggle hook
- Update test cases for AMPToggle component
- Update test cases for Nav component
- Update test cases for ThemesContextProvider component
- Update test cases for TemplateModeOption component
- Update test cases for SiteScanSourcesList component
- Update test cases for Selectable component
- Update test cases for RedirectToggle component
- Update test cases for ProgressBar component
- Update test cases for PluginsContextProvider component
- Update test cases for NavMenu component
- Update test cases for Loading component
- Update test cases for DevToolsToggle component
- Update test cases for ConditionalDetails component
- Update test cases for AMPNotice component
- Update test cases for AMPSettingToggle component
- Update test cases for AmpAdminNotice component
- Update test cases for useValidationErrorStateUpdates hook
- Update test cases for usePostDirtyStateChanges hook
- Update test cases for Error component
- Update test cases for CarouselNav component
- Update test cases for useErrorsFetchingStateChanges hook
@thelovekesh thelovekesh marked this pull request as ready for review May 23, 2023 15:16
@github-actions
Copy link
Contributor

github-actions bot commented May 23, 2023

Plugin builds for eeebbd9 are ready 🛎️!

Copy link
Member

@westonruter westonruter left a comment

Choose a reason for hiding this comment

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

What an epic lift! Great work. Just a couple small comments, and aside from the failing tests, looks really good. (Granted, I'm not an expert on React!)

Comment on lines 232 to 236
// container
// .querySelector(
// `.amp-error--${getErrorTypeClassName(status)} button`
// )
// .click();
Copy link
Member

Choose a reason for hiding this comment

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

Why is this commented-out code here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This code has been migrated to use the click event from @testing-library/react and I missed removing it. Will remove it 👍🏼

Comment on lines -41 to -64
createStore({
reviewLink: 'http://review-link.test',
unreviewedValidationErrors: [
{
clientId: block.clientId,
code: 'DISALLOWED_TAG',
status: 3,
term_id: 12,
title: 'Invalid script: <code>jquery.js</code>',
type: 'js_error',
},
],
validationErrors: [
{
clientId: block.clientId,
code: 'DISALLOWED_TAG',
status: 3,
term_id: 12,
title: 'Invalid script: <code>jquery.js</code>',
type: 'js_error',
},
],
});
});
Copy link
Member

Choose a reason for hiding this comment

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

I recall we chatted about this a bit, but I see why the change of status to 1? Why are unreviewedValidationErrors and validationErrors seemingly merged?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Previously we were using registerStore to create redux stores and then initializing them at required places. With this previously, we were able to initialize it with the initial state of our choice.

With the current implementation, we are initializing our store itself where it has been defined so there will be a single instance of store everywhere. We have combined both of them in one because it's the job of the reducer to decide which validation error will be assigned to unreviewed or reviewed as per

case SET_VALIDATION_ERRORS:
return {
...state,
ampCompatibilityBroken: Boolean(
action.validationErrors.filter(
({ status }) =>
status ===
VALIDATION_ERROR_NEW_REJECTED_STATUS ||
status ===
VALIDATION_ERROR_ACK_REJECTED_STATUS
)?.length
),
reviewedValidationErrors:
action.validationErrors.filter(
({ status }) =>
status ===
VALIDATION_ERROR_ACK_ACCEPTED_STATUS ||
status ===
VALIDATION_ERROR_ACK_REJECTED_STATUS
),
unreviewedValidationErrors:
action.validationErrors.filter(
({ status }) =>
status ===
VALIDATION_ERROR_NEW_ACCEPTED_STATUS ||
status ===
VALIDATION_ERROR_NEW_REJECTED_STATUS
),
keptMarkupValidationErrors:
action.validationErrors.filter(
({ status }) =>
status ===
VALIDATION_ERROR_NEW_REJECTED_STATUS ||
status ===
VALIDATION_ERROR_ACK_REJECTED_STATUS
),
validationErrors: action.validationErrors,
};

Previously, unreviewedValidationErrors was being passed manually(which shouldn't be the case) to check if we are getting the expected results. By passing 1 as status the reducer automatically adds the validation error to the unreviewedValidationErrors state.

Also, see how Gutenberg creates stores: https://github.com/WordPress/gutenberg/blob/trunk/packages/notices/src/store/index.js

@@ -331,6 +331,14 @@ jobs:
env:
COMPOSE_INTERACTIVE_NO_CLI: true


# TODO: Remove it once node version in .nvmrc is updated to >=16.
Copy link
Member

Choose a reason for hiding this comment

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

Wait, why isn't .nvmrc updated to node 18 if the engines.node was updated in package.json?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Aah, I missed reverting the changes in engines. Since many deps in @wordpress/* are outdated, let's keep node to 14.

@thelovekesh thelovekesh force-pushed the upgrade/react-and-nodejs branch 2 times, most recently from e20fd2a to 146e4a3 Compare May 24, 2023 13:25
@westonruter westonruter added this to the v2.4.2 milestone May 24, 2023
Copy link
Member

@westonruter westonruter left a comment

Choose a reason for hiding this comment

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

🎉

westonruter

This comment was marked as duplicate.

@westonruter westonruter merged commit 4d05185 into develop May 24, 2023
@westonruter westonruter deleted the upgrade/react-and-nodejs branch May 24, 2023 17:58
@thelovekesh thelovekesh added Bug Something isn't working Enhancement New feature or improvement of an existing one P2 Low priority Reader Mode WS:Core Work stream for Plugin core and removed Bug Something isn't working Enhancement New feature or improvement of an existing one P2 Low priority Reader Mode WS:Core Work stream for Plugin core labels Jul 13, 2023
@thelovekesh
Copy link
Collaborator Author

QA Passed ✅

  • All JS Unit tests are passing after being migrated to @testing-library/react.
  • AfterActivationSiteScan service only works when React 18 support is present.

@westonruter westonruter added the Changelogged Whether the issue/PR has been added to release notes. label Jul 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelogged Whether the issue/PR has been added to release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants