Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Update @wordpress/components to v. 11.1.1 and @wordpress/base-styles to v. 3.2.0 #3457

Merged
merged 10 commits into from
Dec 3, 2020

Conversation

Aljullu
Copy link
Contributor

@Aljullu Aljullu commented Nov 24, 2020

Fixes #2140.
Fixes #3146.
Fixes #3311.
Fixes #3313.

How to test the changes in this Pull Request:

Regression testing

  1. Verify you can build the project without problems: npm ci && npm run build.
  2. Create a page with all WC Blocks (you can copy and paste —with Ctrl+Shift+Vthis gist) + add the Single Product block & some other Product element blocks.
  3. In the editor, verify all of them render correctly, you can modify their attributes and there are no errors in the browser console.
  4. In the frontend, also verify they render correctly, you can interact with them and there are no errors in the browser console.

Testing #3146

  1. Go to the Checkout block.
  2. Change the value of the Country/Region select.
  3. Verify no errors appear in the browser console.

@Aljullu Aljullu added this to the 4.0.0 milestone Nov 24, 2020
@Aljullu Aljullu requested a review from a team as a code owner November 24, 2020 10:17
@Aljullu Aljullu removed the request for review from a team November 24, 2020 10:17
@Aljullu Aljullu self-assigned this Nov 24, 2020
@Aljullu Aljullu requested a review from haszari November 24, 2020 10:17
@Aljullu Aljullu changed the title WIP: Update @wordpress/components and @wordpress/base-styles to the latest versions WIP: Update @wordpress/components to v. 11.1.1 and @wordpress/base-styles to v. 3.2.0 Nov 24, 2020
@github-actions
Copy link
Contributor

github-actions bot commented Nov 24, 2020

Size Change: +25.1 kB (2%)

Total Size: 1.14 MB

Filename Size Change
build/active-filters-frontend.js 8.87 kB -14 B (0%)
build/active-filters.js 8.93 kB -14 B (0%)
build/all-products-frontend.js 34.8 kB +3.51 kB (10%) ⚠️
build/all-products.js 36.2 kB -76 B (0%)
build/all-reviews.js 9.76 kB -25 B (0%)
build/atomic-block-components/add-to-cart--atomic-block-components/button.js 3.29 kB +2 B (0%)
build/atomic-block-components/add-to-cart-frontend.js 9.02 kB -6 B (0%)
build/atomic-block-components/add-to-cart.js 7.53 kB +2 B (0%)
build/atomic-block-components/button-frontend.js 2.31 kB +1 B
build/atomic-block-components/button.js 839 B +2 B (0%)
build/atomic-block-components/category-list-frontend.js 470 B +1 B
build/atomic-block-components/image-frontend.js 1.68 kB -19 B (1%)
build/atomic-block-components/image.js 1.13 kB -14 B (1%)
build/atomic-block-components/price-frontend.js 2.29 kB -3 B (0%)
build/atomic-block-components/price.js 2.32 kB +1 B
build/atomic-block-components/rating-frontend.js 522 B -1 B
build/atomic-block-components/rating.js 531 B +4 B (0%)
build/atomic-block-components/sale-badge.js 865 B +2 B (0%)
build/atomic-block-components/sku-frontend.js 388 B -1 B
build/atomic-block-components/stock-indicator-frontend.js 568 B -1 B
build/atomic-block-components/summary-frontend.js 918 B +1 B
build/atomic-block-components/tag-list.js 473 B -1 B
build/atomic-block-components/title-frontend.js 1.21 kB -15 B (1%)
build/atomic-block-components/title.js 1.05 kB -15 B (1%)
build/attribute-filter-frontend.js 18.3 kB +29 B (0%)
build/attribute-filter.js 12.5 kB -19 B (0%)
build/blocks.js 3.54 kB +2 B (0%)
build/cart-frontend.js 77.2 kB +5.41 kB (7%) 🔍
build/cart.js 40.3 kB -35 B (0%)
build/checkout-frontend.js 92.4 kB +5.47 kB (5%) 🔍
build/checkout.js 42.6 kB -34 B (0%)
build/featured-category.js 7.72 kB -4 B (0%)
build/featured-product.js 9.94 kB -33 B (0%)
build/handpicked-products.js 7.36 kB +2 B (0%)
build/price-filter-frontend.js 15 kB +90 B (0%)
build/price-filter.js 10.4 kB -16 B (0%)
build/product-best-sellers.js 7.44 kB +1 B
build/product-categories.js 3.24 kB +8 B (0%)
build/product-category.js 8.39 kB +6 B (0%)
build/product-on-sale.js 8 kB +7 B (0%)
build/product-search.js 3.56 kB -1 B
build/product-tag.js 6.53 kB +4 B (0%)
build/product-top-rated.js 7.58 kB +3 B (0%)
build/products-by-attribute.js 8.35 kB +15 B (0%)
build/reviews-by-category.js 11.8 kB -37 B (0%)
build/reviews-by-product.js 13.3 kB -28 B (0%)
build/reviews-frontend.js 9.37 kB -11 B (0%)
build/single-product-frontend.js 38.7 kB +4.67 kB (12%) ⚠️
build/single-product.js 10.1 kB -9 B (0%)
build/style.css 18.4 kB -1 B
build/vendors-style-rtl.css 1.05 kB +20 B (1%)
build/vendors-style.css 1.05 kB +21 B (1%)
build/vendors.js 417 kB +6.2 kB (1%)
ℹ️ View Unchanged
Filename Size Change
build/atomic-block-components/add-to-cart--atomic-block-components/image--atomic-block-components/title.js 335 B 0 B
build/atomic-block-components/category-list.js 477 B 0 B
build/atomic-block-components/sale-badge-frontend.js 858 B 0 B
build/atomic-block-components/sku.js 395 B 0 B
build/atomic-block-components/stock-indicator.js 573 B 0 B
build/atomic-block-components/summary.js 926 B 0 B
build/atomic-block-components/tag-list-frontend.js 467 B 0 B
build/editor-rtl.css 13.9 kB 0 B
build/editor.css 13.9 kB 0 B
build/product-new.js 7.61 kB 0 B
build/style-rtl.css 18.4 kB 0 B
build/vendors--atomic-block-components/price-frontend.js 5.65 kB 0 B
build/wc-blocks-data.js 7.1 kB 0 B
build/wc-blocks-middleware.js 931 B 0 B
build/wc-blocks-registry.js 2.39 kB 0 B
build/wc-payment-method-bacs.js 775 B 0 B
build/wc-payment-method-cheque.js 771 B 0 B
build/wc-payment-method-cod.js 866 B 0 B
build/wc-payment-method-paypal.js 813 B 0 B
build/wc-payment-method-stripe.js 12.1 kB 0 B
build/wc-settings.js 2.59 kB 0 B
build/wc-shared-context.js 1.53 kB 0 B
build/wc-shared-hocs.js 1.66 kB 0 B

compressed-size-action

@Aljullu Aljullu force-pushed the update/wordpress-components branch 5 times, most recently from 36b7ccf to 54161ce Compare November 26, 2020 11:21
@Aljullu
Copy link
Contributor Author

Aljullu commented Nov 26, 2020

Using the explore script (thanks @senadir for adding it!), I analyzed whether the bundle size increase was legit or not. For example, the Checkout frontend script before/after is as follows:

Before:
imatge

After:
imatge

Most of the size increase comes from @wordpress/components, which goes from 34.99KB to 56.11KB. @wordpress/icons and @wordpress/primitives seem to only add 2.33KB.

I investigated a little bit more why @wordpress/components increased so much (are we including components that we don't use?). But I couldn't spot anything off: increases seem legit. As an example, the Button component increased from 774B to 2.47KB, but that's just because more features have been added. I was able to reduce 1KB replacing a for ... of with a regular for loop, but this kind of optimizations would need to be done upstream, and they might make code less-readable, so I'm not sure if creating a PR in GB's repo makes sense at all.

tl;dr: file increases seem legit and there is not an easy way to avoid them other than making optimizations upstream so components are slimmer.

@Aljullu Aljullu changed the title WIP: Update @wordpress/components to v. 11.1.1 and @wordpress/base-styles to v. 3.2.0 Update @wordpress/components to v. 11.1.1 and @wordpress/base-styles to v. 3.2.0 Nov 26, 2020
@Aljullu Aljullu added skip-changelog PRs that you don't want to appear in the changelog. status: needs review labels Nov 26, 2020
@senadir
Copy link
Member

senadir commented Nov 26, 2020

note that bundle comment shows gzipped while the image you showed above is just minified.

Downshift, reakit, and spring-js are the big offenders here, but what changed between the before and after is Downshift (from 10 to 17).

I don't think there's much we can do here really. Our reliance on certain components causes this.

We can eliminate Downshift by using a regular select item instead of downshift and other stuff (see this PR #2281).

I don't think we can do anything in this PR, but having the latest wp.components would allow us to provide fixes upstream.

$gap: $grid-unit-20;
$gap-small: $grid-unit-15;
$gap-smaller: $grid-unit-10;
$gap-smallest: $grid-unit-05;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead of hardcoding px values, let's use the $grid-unit variables from @wordpress/components.

@@ -10,4 +9,4 @@ import withFilteredAttributes from '@woocommerce/base-hocs/with-filtered-attribu
import Block from './block';
import attributes from './attributes';

export default compose( withFilteredAttributes( attributes ) )( Block );
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since @wordpress/compose is no longer extracted, its dependency was generating a new frontend file specific for vendor files. Taking a closer look, it seems like compose() is not required here, so let's remove it.

className="wc-block-components-chip__remove-icon"
focusable="false"
focusable={false}
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 change was automatic when updating the snapshots and seems legit.

expect( noPaymentMethods ).not.toBeNull();
// We might get more than one match because the `speak()` function
// creates an extra `div` with the notice contents used for a11y.
expect( noPaymentMethods.length ).toBeGreaterThanOrEqual( 1 );
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Recent versions of the Notice component generate two elements with the notice text: one for the notice itself and another one used by the speak() a11y function. Our previous test was failing because it was expecting one and only one match.

@@ -32,7 +32,7 @@ const Select = ( {
onChange( selectedItem.key );
} }
options={ options }
value={ value }
value={ value || null }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

value might be undefined, but when it changes from undefined to a value, downshift shows a warning that the component is changing from being uncontrolled to controlled. That can be fixed setting null as the default value when non is selected.

Copy link
Member

@senadir senadir left a comment

Choose a reason for hiding this comment

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

Everything works fine but I'm seeing a small styling issue

image
image

If they're unrelated or are fixed, feel free to merge this.

@Aljullu Aljullu force-pushed the update/wordpress-components branch from e81c312 to 1a86f0e Compare December 2, 2020 17:04
Copy link
Contributor

@haszari haszari left a comment

Choose a reason for hiding this comment

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

Gave this a quick test - played with various blocks in editor and front end and didn't see any problems. FYI I was testing on WP 5.6-beta4.

Thanks for sorting this @Aljullu - it's great to be on recent versions, and nice to see our base CSS variables pulling from Gutenberg/core directly. Nice work 🙌

@@ -165,7 +165,7 @@
"reakit": "1.3.0",
"trim-html": "0.1.9",
"use-debounce": "3.4.3",
"wordpress-components": "npm:@wordpress/components@8.5.0",
"wordpress-components": "npm:@wordpress/components@11.1.1",
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm curious why we have this dep and the other one in devDependencies. What does this mean? Please excuse my ignorance - feel free to point me to docs 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing! Form the docs:

  • "dependencies": Packages required by your application in production.
  • "devDependencies": Packages that are only needed for local development and testing.

In our case:

  • wordpress-components is bundled in frontend scripts, so it's a dependency of the production builds. Because of that, it's listed in dependencies.
  • @wordpress/components is extracted by DependencyExtractionWebpackPlugin, so it's not bundled in the production builds, so it's listed in devDependencies.

For reference, dependencies were re-ordered in this #1663, and there was a similar discussion about @wordpress/components: #1633 (comment).

@Aljullu
Copy link
Contributor Author

Aljullu commented Dec 3, 2020

Thanks for the reviews @senadir & @haszari!

Everything works fine but I'm seeing a small styling issue

Good catch! I could reproduce it too in WC Blocks trunk when using Gutenberg master, so it seems to be unrelated to this PR. I created an issue in WC Admin (woocommerce/woocommerce-admin#5806).

@Aljullu Aljullu merged commit a6cd529 into trunk Dec 3, 2020
@Aljullu Aljullu deleted the update/wordpress-components branch December 3, 2020 13:04
@mikejolley mikejolley mentioned this pull request Dec 7, 2020
20 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
skip-changelog PRs that you don't want to appear in the changelog.
Projects
None yet
3 participants