From 1cbef7dd39de5e6b44b7c0385d82ad379186f9fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albert=20Juh=C3=A9=20Lluveras?= Date: Fri, 12 Jul 2019 13:20:42 +0200 Subject: [PATCH] Cancel debounced functions on unmount (https://github.com/woocommerce/woocommerce-blocks/pull/725) --- .../assets/js/blocks/featured-category/block.js | 4 ++++ .../assets/js/blocks/featured-product/block.js | 4 ++++ .../assets/js/components/product-attribute-control/index.js | 4 ++++ .../assets/js/components/products-control/index.js | 4 ++++ 4 files changed, 16 insertions(+) diff --git a/plugins/woocommerce-blocks/assets/js/blocks/featured-category/block.js b/plugins/woocommerce-blocks/assets/js/blocks/featured-category/block.js index 129f6d964c9..690c2d7c9f3 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/featured-category/block.js +++ b/plugins/woocommerce-blocks/assets/js/blocks/featured-category/block.js @@ -112,6 +112,10 @@ class FeaturedCategory extends Component { this.getCategory(); } + componentWillUnmount() { + this.debouncedGetCategory.cancel(); + } + componentDidUpdate( prevProps ) { if ( prevProps.attributes.categoryId !== this.props.attributes.categoryId ) { this.debouncedGetCategory(); diff --git a/plugins/woocommerce-blocks/assets/js/blocks/featured-product/block.js b/plugins/woocommerce-blocks/assets/js/blocks/featured-product/block.js index b68c2472945..a6b4e53ebbd 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/featured-product/block.js +++ b/plugins/woocommerce-blocks/assets/js/blocks/featured-product/block.js @@ -96,6 +96,10 @@ class FeaturedProduct extends Component { this.getProduct(); } + componentWillUnmount() { + this.debouncedGetProduct.cancel(); + } + componentDidUpdate( prevProps ) { if ( prevProps.attributes.productId !== this.props.attributes.productId ) { this.debouncedGetProduct(); diff --git a/plugins/woocommerce-blocks/assets/js/components/product-attribute-control/index.js b/plugins/woocommerce-blocks/assets/js/components/product-attribute-control/index.js index e6fb8235067..5d4d9f1b897 100644 --- a/plugins/woocommerce-blocks/assets/js/components/product-attribute-control/index.js +++ b/plugins/woocommerce-blocks/assets/js/components/product-attribute-control/index.js @@ -51,6 +51,10 @@ class ProductAttributeControl extends Component { } ); } + componentWillUnmount() { + this.debouncedGetTerms.cancel(); + } + componentDidUpdate( prevProps, prevState ) { if ( prevState.attribute !== this.state.attribute ) { this.debouncedGetTerms(); diff --git a/plugins/woocommerce-blocks/assets/js/components/products-control/index.js b/plugins/woocommerce-blocks/assets/js/components/products-control/index.js index b34928f1465..98090ddee8a 100644 --- a/plugins/woocommerce-blocks/assets/js/components/products-control/index.js +++ b/plugins/woocommerce-blocks/assets/js/components/products-control/index.js @@ -35,6 +35,10 @@ class ProductsControl extends Component { } ); } + componentWillUnmount() { + this.debouncedOnSearch.cancel(); + } + onSearch( search ) { const { selected } = this.props; getProducts( { selected, search } )