Improve hidden tab suppression/fix rapid requests
This fixes the rapid request problem that was happening when switching tabs while having timed out requests. It changes the approach from suppressing the actions sent out to preventing the read function from being called at all. I think the original problem has occurred because the original approach was relying on an internal implementation of apiFetch from wp.data. This new approach does not have such a dependency. It prevents apiFetch from even being called. However, in the process, it will also prevent any newly required resources from being fetched if the user manages to switch tabs before it is requested. (e.g. refresh, then switch tabs quickly).
This commit is contained in:
parent
8ed63c5547
commit
78e85f87c3
|
@ -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 ),
|
||||
|
|
|
@ -19,11 +19,6 @@ function createStore( name ) {
|
|||
function createDataHandlers( store ) {
|
||||
return {
|
||||
dataRequested: resourceNames => {
|
||||
const { resources } = store.getState();
|
||||
const newResources = resourceNames.some( resourceName => ! resources[ resourceName ] );
|
||||
if ( ! newResources && document.hidden ) {
|
||||
return;
|
||||
}
|
||||
store.dispatch( {
|
||||
type: 'FRESH_DATA_REQUESTED',
|
||||
resourceNames,
|
||||
|
|
Loading…
Reference in New Issue