From 007ff933cebedbe9d1507d830feca42096cd6d5d Mon Sep 17 00:00:00 2001 From: Kevin Killingsworth Date: Tue, 9 Apr 2019 09:56:25 -0500 Subject: [PATCH] Fix withSelect to release resources on unmount (https://github.com/woocommerce/woocommerce-admin/pull/1999) * Add fresh-data dev info support for dev builds. This adds support for dev info to be accessed from the JavaScript console for more information about resources handled by fresh-data. * Update fresh-data to 0.6.0 * Fix withSelect to release resources on unmount Previously, withSelect wasn't releasing resources from fresh-data when it was unmounting. This fixes that behavior and now clears a component's requirements correctly when unmounting. --- plugins/woocommerce-admin/client/wc-api/with-select.js | 3 +-- plugins/woocommerce-admin/client/wc-api/wp-data-store/index.js | 3 +++ 2 files changed, 4 insertions(+), 2 deletions(-) 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 ); + }, }; }