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

spike: react 18 update #925

Conversation

ecRobertEngel
Copy link
Contributor

Proof of concept implementation of a React 18 and ChakraUI 2 upgrade

Description

Please be aware that this is not intended to be merged.
As I had to update pwa-kit for a project to React 18 I wanted to share my findings with you. While the template-retail-react-app is running very stable there are still issues with test files that I have not resolved.

Most important change for the upgrade is the change in the main.jsx with the changed hydration API that requires a manual callback

Some notes about testing:

  • @testing-library/react had to be upgraded to also support React 18
  • @testing-library/react-hooks is (about to be) deprecated. There a migration guide available. Most changes have already been made here but the original package is still included
  • Most test problems seem to be related to async handling but I have not taken a deeper look as we use another test setup.

Types of Changes

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Documentation update
  • Breaking change (could cause existing functionality to not work as expected)
  • Other changes (non-breaking changes that does not fit any of the above)

Breaking changes include:

  • Removing a public function or component or prop
  • Adding a required argument to a function
  • Changing the data type of a function parameter or return value
  • Adding a new peer dependency to package.json

Changes

  • (change1)

How to Test-Drive This PR

  • (step1)

Checklists

General

  • Changes are covered by test cases
  • CHANGELOG.md updated with a short description of changes (not required for documentation updates)

Accessibility Compliance

You must check off all items in one of the follow two lists:

  • There are no changes to UI

or...

Localization

  • Changes include a UI text update in the Retail React App (which requires translation)

@ecRobertEngel ecRobertEngel requested a review from a team as a code owner January 23, 2023 17:29
@salesforce-cla
Copy link

Thanks for the contribution! Unfortunately we can't verify the commit author(s): Robert Engel <r***@e***.com>. One possible solution is to add that email to your GitHub account. Alternatively you can change your commits to another email and force push the change. After getting your commits associated with your GitHub account, sign the Salesforce.com Contributor License Agreement and this Pull Request will be revalidated.

await waitFor(() => {
expect(result.current.mutation.isSuccess).not.toBe(initialSuccess)
})

expect(result.current.mutation.isSuccess).toBe(true)

// On successful mutation, the query cache gets updated too. Let's assert it.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The assertion for invalidate?.forEach and remove?.forEach fail. To be honest I don't really know why. 🤷‍♂️

@@ -198,7 +198,7 @@ RecommendedProducts.propTypes = {
recommender: PropTypes.string,

/* The product IDs to use for recommendation context */
products: PropTypes.arrayOf(PropTypes.string),
products: PropTypes.arrayOf(PropTypes.object),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not actually part of the needed changes but an existing error. I just fixed it to have a clean console to verify that pwa-kit is behaving as expected

Copy link
Collaborator

@bfeister bfeister left a comment

Choose a reason for hiding this comment

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

@ecRobertEngel Thanks so much for working on this! 🙏 Two things:

  1. Make sure you sign the CLA if we're going to merge this
  2. @natemarcus (our product manager) will need to set the date for this release so that we can synchronize other release/v3 changes we expect to ship along with this since the React 18 upgrade is a breaking change in the SDK

@bfeister bfeister added the Acknowledged Team has responded to issue label Jan 23, 2023
@ecRobertEngel
Copy link
Contributor Author

Currently the following issues with tests are still unresolved:


pwa-kit

search/index.test.js - renders Popover if recent searches populated: Only finds one element.

use-auth-modal.test.js - Allows customer to create an account: callback is not getting invoked.

cart/index.test.js - Can apply and remove product-level coupon code with promotion: finds element even though it should be removed.

cart/index.test.jst - Can update item quantity from product view modal: Increment does not seem to be triggered

cart/index.test.jst - Can update item quantity in the cart: Increment does not seem to be triggered

account/index.test.js - Allows customer to sign out: Fetch error


commerce-react-sdk

mutation.test.ts - The checks for assertInvalidateQuery and assertRemoveQuery fail


As I said as we use cypress component tests in our project I don't have too much experience with the jest tests here. So maybe the issues are obvious to a more experienced dev here.

@ecRobertEngel
Copy link
Contributor Author

ecRobertEngel commented Jan 24, 2023

There are two things that are still causing hydration issues. They are related to the use of isServer logic. This is the Pagination and the PageHeader components.

Steps to reproduce either : Navigate to a PLP from client side and reload or navigate directly to a PLP page

If the isServer logic is removed both work without issue. There might be changes needed to handle this. For the moment I won't touch it here.

@ecRobertEngel
Copy link
Contributor Author

There are two things that are still causing hydration issues. They are related to the use of isServer logic. This is the Pagination and the PageHeader components.

Steps to reproduce either : Navigate to a PLP from client side and reload or navigate directly to a PLP page

If the isServer logic is removed both work without issue. There might be changes needed to handle this. For the moment I won't touch it here.

The solution is to use a hook instead of the checks against the window global in the component. A possible hook has been added to the PR.

@bfeister bfeister added this to the v3 milestone Feb 10, 2023
@bfeister
Copy link
Collaborator

@ecRobertEngel Wanted to say thank you again for working on this and the work will definitely be useful to us soon. I've added the v3 milestone as this will be part of v3 which we are beginning to coordinate here

@natemarcus we have our own internal backlog but for those parts of v3 that are requested by customers (like this) I've added to milestones here

https://github.com/SalesforceCommerceCloud/pwa-kit/milestone/1

@vmarta
Copy link
Contributor

vmarta commented Feb 15, 2023

Closing this for now. Looks like it'll be useful later for our v3 work.

@vmarta vmarta closed this Feb 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Acknowledged Team has responded to issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants