diff --git a/plugins/woocommerce-admin/client/wc-api/with-select.js b/plugins/woocommerce-admin/client/wc-api/with-select.js index cf6bf5fcefe..cf768557e37 100644 --- a/plugins/woocommerce-admin/client/wc-api/with-select.js +++ b/plugins/woocommerce-admin/client/wc-api/with-select.js @@ -59,7 +59,6 @@ const withSelect = mapSelectToProps => getNextMergeProps( props ) { const storeSelectors = {}; const onCompletes = []; - const onUnmounts = {}; const componentContext = { component: this }; const getStoreFromRegistry = ( key, registry, context ) => { @@ -72,7 +71,7 @@ const withSelect = mapSelectToProps => // We give it a context, and we check for a "resolve" const { selectors, onComplete, onUnmount } = selectorsForKey( context ); onComplete && onCompletes.push( onComplete ); - onUnmount && ( onUnmounts[ key ] = onUnmount ); + onUnmount && ( this.onUnmounts[ key ] = onUnmount ); storeSelectors[ key ] = selectors; } else { storeSelectors[ key ] = selectorsForKey; diff --git a/plugins/woocommerce-admin/client/wc-api/wp-data-store/index.js b/plugins/woocommerce-admin/client/wc-api/wp-data-store/index.js index ab33d0c390a..ee2e5f4ef5a 100644 --- a/plugins/woocommerce-admin/client/wc-api/wp-data-store/index.js +++ b/plugins/woocommerce-admin/client/wc-api/wp-data-store/index.js @@ -29,6 +29,9 @@ function createWcApiStore() { apiClient.setComponentRequirements( component, componentRequirements ); } }, + onUnmount: () => { + apiClient.clearComponentRequirements( component ); + }, }; }