Merge pull request woocommerce/woocommerce-admin#2387 from woocommerce/fix/2365-improve-tab-switching-read-suppression

Improve hidden tab suppression/fix rapid requests
This commit is contained in:
Paul Sealock 2019-06-13 09:22:48 +12:00 committed by GitHub
commit ed21ccf62e
2 changed files with 9 additions and 3 deletions

View File

@ -36,6 +36,11 @@ function createWcApiSpec() {
},
operations: {
read( resourceNames ) {
if ( document.hidden ) {
// Don't do any read updates while the tab isn't active.
return [];
}
return [
...imports.operations.read( resourceNames ),
...items.operations.read( resourceNames ),

View File

@ -19,11 +19,12 @@ function createStore( name ) {
function createDataHandlers( store ) {
return {
dataRequested: resourceNames => {
const { resources } = store.getState();
const newResources = resourceNames.some( resourceName => ! resources[ resourceName ] );
if ( ! newResources && document.hidden ) {
// This is a temporary fix until it can be resolved upstream in fresh-data.
// See: https://github.com/woocommerce/woocommerce-admin/pull/2387/files#r292355276
if ( document.hidden ) {
return;
}
store.dispatch( {
type: 'FRESH_DATA_REQUESTED',
resourceNames,