-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Checkout: create shopping-cart package and ShoppingCartProvider #46532
Conversation
Here is how your PR affects size of JS and CSS bundles shipped to the user's browser: Sections (~383 bytes added 📈 [gzipped])
Sections contain code specific for a given set of routes. Is downloaded and parsed only when a particular route is navigated to. Async-loaded Components (~2710 bytes removed 📉 [gzipped])
React components that are loaded lazily, when a certain part of UI is displayed for the first time. Legend What is parsed and gzip size?Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory. Generated by performance advisor bot at iscalypsofastyet.com. |
It looks as though the CartStore begins polling as soon as the application loads when CartStore.setSelectedSiteId is called. |
cea7da8
to
40deeed
Compare
Things that would need to be internalized or injected if we want to move this to its own package:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WordPress Desktop CI Failure for job "wp-desktop-mac".
@sirbrillig please inspect this job's build steps for breaking changes at this link. For temporal failures, you may try to "Rerun Workflow from Failed".
Please also ensure this branch is rebased off latest Calypso.
wp-desktop ci passing, closing review
@nbloomf At some point in the near future, I'd love your help figuring out a useful test plan for this, given the notes I wrote in the description. |
Ah, I realized a bug: we need to know when the CartStore has finished updating in order to continue after we wait for a race condition to resolve. That's what's causing the tests to fail. To reproduce: add a domain to your cart. 😩 I wish we could remove this dependency on the CartStore but I guess we can't just yet. |
Update: Disregard this; I forgot to This may be a problem local to me, but even after restarting calypso I'm getting errors like this:
and similar console errors: |
I tried testing the userless checkout flow and ran into some bugs. I was able to reproduce this behavior with both this branch and master, but not in production; i'm not sure what is causing this yet but it appears to be vaguely cart related. Here are my steps to reproduce.
|
For later reference, the race condition I observed (and there may be others) is triggered when the domain purchase button is clicked. Ideally, it would wait for the cart update to complete before running the redirect. |
It turns out there were actually two race conditions: the one with the |
The |
There we go, I figured it out. It was because the |
e9e47b8
to
7663298
Compare
Rebased to fix a conflict, as well as to squash some of the refactors down into more atomic commits. Reviewing each commit should be more reasonable now. |
7663298
to
5cc918a
Compare
Previously, the concept of initializing the cart happened only once. Now, the CART_RELOAD action can cause another initialize, so useInitializeCartFromServer cannot count on a flag to know if it should allow an initialize or not. Instead, we rely on the cache status, which is notified that we are fetching the initial data by a new action on the shopping cart reducer.
It does not exist.
They are all internal only.
25fa528
to
19b38ee
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We went over the code changes in a pair session, and I did some testing to make sure I was able to complete checkout in the new-site flow as well as userless. I didn't see any problems and the code looks good. Nice work!
Changes proposed in this Pull Request
This creates a new wrapper component,
ShoppingCartProvider
, which can be used along with its hook,useShoppingCart
to provide access to the shopping cart to any component in calypso (assuming the provider is used on that route). This PR only wraps checkout in the provider, but it can be used on other routes in the future to replace theCartData
provider.For components which cannot use hooks, this also adds a
withShoppingCart
HOC that provides the same data.This also creates a new package in the monorepo for the above and the rest of the shopping-cart functions and types called
@automattic/shopping-cart
.Testing instructions
This is a big change for new checkout, but the shopping cart is so heavily interwoven into all aspects of checkout, if anything works, it's very likely that everything will work. The API of the shopping cart manager has not changed with this PR (except for adding a way to reload the cart). This PR really just moves where the functions are defined and where they are created at runtime.
Reviewing this PR is probably most easily done commit-by-commit.
Notable things that have changed and should be verified:
no-site
behavior explicitly (this is done by the domain-only singup e2e tests).isLoggedOutCart
andisNoSiteCart
behaviors, but they are moved around by this change so they should be tested. We may be able to learn more by using the test instructions in Registrationless checkout: Integration PR #44206