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

Checkout: Convert CompositeCheckout component to TypeScript #46758

Merged
merged 20 commits into from Nov 3, 2020

Conversation

sirbrillig
Copy link
Member

@sirbrillig sirbrillig commented Oct 25, 2020

Changes proposed in this Pull Request

This converts the main component in new checkout, CompositeCheckout, to TypeScript. In the process, it fixes several small bugs and type errors.

Testing instructions

This touches nearly all aspects of checkout, but it's impossible to test them all, and like many other recent refactors, if anything serious is broken by this, it should be obvious quickly.

Notable changes:

  • arguments has been removed from the THANK_YOU_URL_GENERATED analytics event. They have actually been missing since Checkout: Convert getThankYouUrl to TypeScript #46423. It would be nice to add them back in, but getting them out of the hook is actually non-trivial and I'd rather that be in its own PR. For the moment, this just removes the unused property. This should have no effect, but it might be worth examining the event when it runs to be sure it's working.
  • This movesdoesValueExist to a top-level helper in the composite checkout directory which can be used as [].filter(doesValueExist) in place of [].filter(Boolean) to please TypeScript. This should have no user-facing effect as long as it filters out falsy values correctly. If it doesn't, we'd probably see lots of errors about adding products when no product add errors exist.
  • This makes useRedirectIfCartEmpty more explicit about when it will and won't redirect; there's now a single argument, doNotRedirect, which is used for that decision, putting the logic fully in the consumer. Worth testing that we are still redirected when we'd expect to be, and are not redirected if the cart is empty and an invalid product slug is in the URL.

@matticbot
Copy link
Contributor

@sirbrillig sirbrillig self-assigned this Oct 25, 2020
@matticbot
Copy link
Contributor

matticbot commented Oct 25, 2020

Here is how your PR affects size of JS and CSS bundles shipped to the user's browser:

App Entrypoints (~46 bytes added 📈 [gzipped])

name        parsed_size           gzip_size
entry-main       +164 B  (+0.0%)      +46 B  (+0.0%)

Common code that is always downloaded and parsed every time the app is loaded, no matter which route is used.

Sections (~628 bytes removed 📉 [gzipped])

name             parsed_size           gzip_size
checkout             -3183 B  (-0.2%)     -623 B  (-0.1%)
site-purchases         -34 B  (-0.0%)       -5 B  (-0.0%)
purchases              -34 B  (-0.0%)       +4 B  (+0.0%)
plans                  -34 B  (-0.0%)       +0 B
migrate                -34 B  (-0.0%)       -6 B  (-0.0%)
jetpack-connect        -34 B  (-0.0%)       +1 B  (+0.0%)
domains                -34 B  (-0.0%)       +1 B  (+0.0%)

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 (~878 bytes removed 📉 [gzipped])

name                                                 parsed_size           gzip_size
async-load-calypso-blocks-editor-checkout-modal          -4042 B  (-0.4%)     -902 B  (-0.3%)
async-load-calypso-blocks-inline-help                     +164 B  (+0.1%)      +41 B  (+0.1%)
async-load-signup-steps-plans-atomic-store                 -34 B  (-0.0%)       -6 B  (-0.0%)
async-load-signup-steps-plans                              -34 B  (-0.0%)       -5 B  (-0.0%)
async-load-signup-steps-domains                            -34 B  (-0.0%)       -4 B  (-0.0%)
async-load-design-blocks                                   -34 B  (-0.0%)       +0 B
async-load-calypso-components-web-preview-component        -34 B  (-0.0%)       -2 B  (-0.0%)

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.
Gzip Size: Compressed size of the JS and CSS files. This much data needs to be downloaded over network.

Generated by performance advisor bot at iscalypsofastyet.com.

@sirbrillig sirbrillig force-pushed the update/calypso-composite-checkout-to-typescript branch 2 times, most recently from 02dd334 to 10ac19e Compare October 26, 2020 16:30
@sirbrillig sirbrillig added [Status] Needs e2e Testing [Feature] Checkout The checkout screen and process for purchases made on WordPress.com. labels Oct 26, 2020
@sirbrillig sirbrillig changed the base branch from master to remove/cart-item-imports-from-composite-checkout October 26, 2020 16:47
@sirbrillig sirbrillig marked this pull request as ready for review October 26, 2020 16:50
@sirbrillig sirbrillig requested a review from a team as a code owner October 26, 2020 16:50
@matticbot matticbot added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Oct 26, 2020
@sirbrillig sirbrillig force-pushed the update/calypso-composite-checkout-to-typescript branch from fd4c9bb to 0d9325a Compare October 27, 2020 19:55
@sirbrillig sirbrillig force-pushed the remove/cart-item-imports-from-composite-checkout branch from 8bed690 to 783d5c1 Compare November 2, 2020 16:16
@sirbrillig sirbrillig force-pushed the update/calypso-composite-checkout-to-typescript branch from 242bc6a to ad20fe0 Compare November 2, 2020 16:18
@nbloomf
Copy link
Contributor

nbloomf commented Nov 2, 2020

I see some odd behavior when renewing a plan; it also happens on master so is not related to this PR. Reported at https://github.com/Automattic/payments-shilling/issues/37

@sirbrillig
Copy link
Member Author

Yeah, good find. We'll need to modify the getThankYouPageUrl function to be aware of the difference between site-level and account-level. Or maybe just always default to site-level? Anyway, we can figure that out later.

@nbloomf
Copy link
Contributor

nbloomf commented Nov 2, 2020

I tried a bunch of flows and didn't see any behavioral bugs. This is not exhaustive, but as you say, exhaustive testing would take a long time and if this does break something it should be clear quickly.

  • Renewing a plan
  • Upgrading a plan from a persistent cart
  • Adding a plan upgrade to the cart from the URL
  • Emptying the cart from within checkout

I checked for a "THANK_YOU_URL_GENERATED" event, and it looks normal:

Screen Shot 2020-11-02 at 3 49 56 PM

I did see a couple of relevant looking console errors while navigating around checkout, but they did not cause any visible problems or prevent checkout from completing:

Screen Shot 2020-11-02 at 3 53 41 PM

(Don't think these are related to each other)

Screen Shot 2020-11-02 at 3 53 53 PM

Copy link
Contributor

@nbloomf nbloomf left a comment

Choose a reason for hiding this comment

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

Looks good and works as described!

@sirbrillig sirbrillig force-pushed the remove/cart-item-imports-from-composite-checkout branch from 32302b5 to 9a281c6 Compare November 2, 2020 22:30
Base automatically changed from remove/cart-item-imports-from-composite-checkout to master November 3, 2020 16:03
There are several reasons why useRedirectIfCartEmpty should be disabled,
and we keep adding more. Rather than passing all of those values into
the hook and making it know how to deal with each one, this puts that
responsibility on the caller by replacing them with a single boolean
arugment called `doNotRedirect`.
When originally typing the WPCOM payment method strings, we were still
learning TypeScript and we created object types for each one as
`WPCOMPaymentMethodClass`. However, we need to know the string values in
some places, and so this simplifies `WPCOMPaymentMethodClass` by
creating a separate type for that string.
I believe that this was a mistake when the type was created. In use, it
appears to actually be an object.
Both of these types are objects, not arrays.

I believe this was a mistake when these types were created, possibly
because when these properties are returned empty, they are an empty
array due to PHP's syntax.
This will make it easier to locate dependencies outside of
composite-checkout as we try to reduce those dependencies.
The reducer always returns at least an object.
@sirbrillig sirbrillig force-pushed the update/calypso-composite-checkout-to-typescript branch from ad20fe0 to f7e9620 Compare November 3, 2020 16:06
@sirbrillig
Copy link
Member Author

Rebased after #46671

@sirbrillig sirbrillig merged commit 74c2907 into master Nov 3, 2020
@sirbrillig sirbrillig deleted the update/calypso-composite-checkout-to-typescript branch November 3, 2020 20:03
@matticbot matticbot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Nov 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Checkout The checkout screen and process for purchases made on WordPress.com.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants