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:
commit
ed21ccf62e
|
@ -36,6 +36,11 @@ function createWcApiSpec() {
|
||||||
},
|
},
|
||||||
operations: {
|
operations: {
|
||||||
read( resourceNames ) {
|
read( resourceNames ) {
|
||||||
|
if ( document.hidden ) {
|
||||||
|
// Don't do any read updates while the tab isn't active.
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
...imports.operations.read( resourceNames ),
|
...imports.operations.read( resourceNames ),
|
||||||
...items.operations.read( resourceNames ),
|
...items.operations.read( resourceNames ),
|
||||||
|
|
|
@ -19,11 +19,12 @@ function createStore( name ) {
|
||||||
function createDataHandlers( store ) {
|
function createDataHandlers( store ) {
|
||||||
return {
|
return {
|
||||||
dataRequested: resourceNames => {
|
dataRequested: resourceNames => {
|
||||||
const { resources } = store.getState();
|
// This is a temporary fix until it can be resolved upstream in fresh-data.
|
||||||
const newResources = resourceNames.some( resourceName => ! resources[ resourceName ] );
|
// See: https://github.com/woocommerce/woocommerce-admin/pull/2387/files#r292355276
|
||||||
if ( ! newResources && document.hidden ) {
|
if ( document.hidden ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
store.dispatch( {
|
store.dispatch( {
|
||||||
type: 'FRESH_DATA_REQUESTED',
|
type: 'FRESH_DATA_REQUESTED',
|
||||||
resourceNames,
|
resourceNames,
|
||||||
|
|
Loading…
Reference in New Issue