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: Modify useCreateExistingCards to only rememoize only when ids change #49057

Merged
merged 1 commit into from
Feb 1, 2021

Conversation

sirbrillig
Copy link
Member

@sirbrillig sirbrillig commented Jan 20, 2021

The useCreateExistingCards hook creates composite-checkout payment method objects and has a dependency on an array of objects from the stored cards endpoint. Previously, the payment methods were recreated any time the stored cards array changed. Since the array is an object, this is an referential equality check.

Here, we change the hook such that it will only recreate the payment methods if the ids of the stored cards change. Since the ids are numbers or strings, this is a primitive value check.

This will make it easier to call the hook without recreating the payment methods each time since the stored card data typically comes from the getStoredCards selector which always returns a new array.

This is part of #48966

Testing instructions

  • Visit checkout when you have no stored cards and be sure that there are no errors.
  • Visit checkout with some stored cards and be sure there are no errors and that your stored cards show up as payment methods.

The `useCreateExistingCards` hook creates composite-checkout payment
method objects and has a dependency on an array of objects from the
stored cards endpoint. Previously, the payment methods were recreated
any time the stored cards array changed. Since the array is an object,
this is an referential equality check.

Here, we change the hook such that it will only recreate the payment
methods if the ids of the stored cards change. Since the ids are numbers
or strings, this is a primitive value check.

This will make it easier to call the hook without recreating the payment
methods each time since the stored card data typically comes from the
`getStoredCards` selector which always returns a new array.
@sirbrillig sirbrillig requested a review from a team as a code owner January 20, 2021 00:16
@matticbot
Copy link
Contributor

@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 Jan 20, 2021
@sirbrillig sirbrillig self-assigned this Jan 20, 2021
@sirbrillig sirbrillig added [Feature] Checkout The checkout screen and process for purchases made on WordPress.com. [Estimate] 1 labels Jan 20, 2021
@matticbot
Copy link
Contributor

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

Sections (~353 bytes added 📈 [gzipped])

name            parsed_size           gzip_size
site-purchases       +415 B  (+0.0%)     +113 B  (+0.0%)
purchases            +415 B  (+0.0%)     +121 B  (+0.0%)
checkout             +415 B  (+0.0%)     +119 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 (~121 bytes added 📈 [gzipped])

name                                             parsed_size           gzip_size
async-load-calypso-blocks-editor-checkout-modal       +415 B  (+0.0%)     +121 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.

@nbloomf
Copy link
Contributor

nbloomf commented Feb 1, 2021

I tested by entering checkout with stored cards, viewing the list of payment methods, then (in a separate tab) deleting my stored cards, and reloading checkout. In both cases the payment method list behaved as expected with no errors or warnings.

@nbloomf nbloomf self-requested a review February 1, 2021 20:23
@nbloomf nbloomf added [Status] Ready to Merge and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Feb 1, 2021
@sirbrillig sirbrillig merged commit e4be3e1 into trunk Feb 1, 2021
@sirbrillig sirbrillig deleted the update/use-create-existing-cards-memoize-on-id branch February 1, 2021 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Estimate] 1 [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.

3 participants