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

Avoid exposing receiveCart to extensions #4730

Merged
merged 1 commit into from
Sep 13, 2021

Conversation

Aljullu
Copy link
Contributor

@Aljullu Aljullu commented Sep 13, 2021

While working on #4688, I found a couple of instances where we were passing receiveCart to slot fills so it was available by extensions. This PR fixes that.

Question: I wonder if we should create a hook that acts as a wrapper of useStoreCart() and automatically excludes receiveCart, so it can be used safely when making data available to extensions.

Testing

  1. Smoke test Cart & Checkout blocks with an extension like WC Subscriptions and verify there are no JS errors in the console and everything works as expected.

Changelog

Removed receiveCart method that was exposed in a couple of SlotFills by mistake.

@Aljullu Aljullu added status: needs review type: bug The issue/PR concerns a confirmed bug. block: cart Issues related to the cart block. block: checkout Issues related to the checkout block. labels Sep 13, 2021
@Aljullu Aljullu self-assigned this Sep 13, 2021
@Aljullu Aljullu requested a review from a team as a code owner September 13, 2021 12:19
@Aljullu Aljullu requested review from mikejolley and removed request for a team September 13, 2021 12:19
@github-actions
Copy link
Contributor

Size Change: +96 B (0%)

Total Size: 1.19 MB

Filename Size Change
build/cart-frontend.js 91.1 kB +26 B (0%)
build/cart.js 46 kB +24 B (0%)
build/checkout-frontend.js 95.2 kB +16 B (0%)
build/checkout-i2.js 49.4 kB +14 B (0%)
build/checkout.js 49 kB +16 B (0%)
ℹ️ View Unchanged
Filename Size
build/active-filters-frontend.js 8.38 kB
build/active-filters.js 8.01 kB
build/all-products-frontend.js 23.1 kB
build/all-products.js 37 kB
build/all-reviews.js 9.59 kB
build/atomic-block-components/add-to-cart--atomic-block-components/button--atomic-block-components/image---a7e2bb9b.js 2.65 kB
build/atomic-block-components/add-to-cart--atomic-block-components/button.js 1.81 kB
build/atomic-block-components/add-to-cart--atomic-block-components/image--atomic-block-components/title.js 333 B
build/atomic-block-components/add-to-cart-frontend.js 8.38 kB
build/atomic-block-components/add-to-cart.js 7.73 kB
build/atomic-block-components/button-frontend.js 1.74 kB
build/atomic-block-components/button.js 875 B
build/atomic-block-components/category-list-frontend.js 469 B
build/atomic-block-components/category-list.js 476 B
build/atomic-block-components/image-frontend.js 1.88 kB
build/atomic-block-components/image.js 1.35 kB
build/atomic-block-components/price-frontend.js 2.09 kB
build/atomic-block-components/price.js 2.11 kB
build/atomic-block-components/rating-frontend.js 563 B
build/atomic-block-components/rating.js 567 B
build/atomic-block-components/sale-badge-frontend.js 860 B
build/atomic-block-components/sale-badge.js 868 B
build/atomic-block-components/sku-frontend.js 388 B
build/atomic-block-components/sku.js 394 B
build/atomic-block-components/stock-indicator-frontend.js 611 B
build/atomic-block-components/stock-indicator.js 612 B
build/atomic-block-components/summary-frontend.js 905 B
build/atomic-block-components/summary.js 911 B
build/atomic-block-components/tag-list-frontend.js 466 B
build/atomic-block-components/tag-list.js 473 B
build/atomic-block-components/title-frontend.js 1.44 kB
build/atomic-block-components/title.js 1.29 kB
build/attribute-filter-frontend.js 18.7 kB
build/attribute-filter.js 12.2 kB
build/blocks-checkout.js 21 kB
build/checkout-i2-frontend.js 52.5 kB
build/featured-category.js 7.81 kB
build/featured-product.js 9.51 kB
build/handpicked-products.js 6.35 kB
build/mini-cart-component-frontend.js 36.2 kB
build/mini-cart-frontend.js 2.35 kB
build/mini-cart.js 2.35 kB
build/price-filter-frontend.js 14.5 kB
build/price-filter.js 9.7 kB
build/price-format.js 1.37 kB
build/product-best-sellers.js 6.7 kB
build/product-categories.js 3.38 kB
build/product-category.js 7.56 kB
build/product-new.js 6.85 kB
build/product-on-sale.js 7.2 kB
build/product-search.js 2.66 kB
build/product-tag.js 6.67 kB
build/product-top-rated.js 6.82 kB
build/products-by-attribute.js 7.79 kB
build/reviews-by-category.js 11.6 kB
build/reviews-by-product.js 13.1 kB
build/reviews-frontend.js 9.02 kB
build/single-product-frontend.js 26.2 kB
build/single-product.js 9.79 kB
build/stock-filter-frontend.js 8.75 kB
build/stock-filter.js 7.73 kB
build/vendors--atomic-block-components/add-to-cart-frontend.js 20.3 kB
build/vendors--atomic-block-components/price-frontend.js 5.72 kB
build/wc-blocks-data.js 11.1 kB
build/wc-blocks-editor-style-rtl.css 15.5 kB
build/wc-blocks-editor-style.css 15.5 kB
build/wc-blocks-google-analytics.js 1.98 kB
build/wc-blocks-middleware.js 1.47 kB
build/wc-blocks-registry.js 3.68 kB
build/wc-blocks-shared-context.js 1.54 kB
build/wc-blocks-shared-hocs.js 1.75 kB
build/wc-blocks-style-rtl.css 20.6 kB
build/wc-blocks-style.css 20.6 kB
build/wc-blocks-vendors-style-rtl.css 1.37 kB
build/wc-blocks-vendors-style.css 1.37 kB
build/wc-blocks-vendors.js 254 kB
build/wc-blocks.js 3.5 kB
build/wc-payment-method-bacs.js 806 B
build/wc-payment-method-cheque.js 806 B
build/wc-payment-method-cod.js 898 B
build/wc-payment-method-paypal.js 839 B
build/wc-payment-method-stripe.js 12.2 kB
build/wc-settings.js 2.92 kB

compressed-size-action

@@ -150,7 +150,7 @@ const ShippingRatesControl = ( {
// Prepare props to pass to the ExperimentalOrderShippingPackages slot fill.
// We need to pluck out receiveCart.
// eslint-disable-next-line no-unused-vars
const { extensions, ...cart } = useStoreCart();
Copy link
Member

Choose a reason for hiding this comment

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

This was already removed (according to the comment) so it seems like it slipped in by accident on a recent refactor. Great catch!

@senadir
Copy link
Member

senadir commented Sep 13, 2021

I wonder if we should create a hook that acts as a wrapper of useStoreCart() and automatically excludes receiveCart, so it can be used safely when making data available to extensions.

I did think about that, we have a pattern of doing that recently, e.g. useValidation and useCheckoutExtensionData. However, currently, we don’t have anything extra to add to what's returned to useCart so I think we can hold on to this idea until this interface evolves. Given that creating and removing this hook wouldn’t break anything in the future, it's a safe option to add it both now or later, but I would avoid adding complexity to the codebase.

@Aljullu
Copy link
Contributor Author

Aljullu commented Sep 13, 2021

Makes sense. Thanks for the review @senadir!

@Aljullu Aljullu merged commit f4f6f48 into trunk Sep 13, 2021
@Aljullu Aljullu deleted the fix/avoid-exposing-receiveCart-to-extensions branch September 13, 2021 13:49
@Aljullu Aljullu modified the milestones: 5.9.0, 6.0.0 Sep 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
block: cart Issues related to the cart block. block: checkout Issues related to the checkout block. type: bug The issue/PR concerns a confirmed bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants