Product Button: use setTimeout when requestIdleCallback isn't available (https://github.com/woocommerce/woocommerce-blocks/pull/11125)
This commit is contained in:
parent
c47babe628
commit
9dd8dd321f
|
@ -64,6 +64,10 @@ const injectNotice = ( domNode: Element, errorMessage: string ) => {
|
||||||
} );
|
} );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// RequestIdleCallback is not available in Safari, so we use setTimeout as an alternative.
|
||||||
|
const callIdleCallback =
|
||||||
|
window.requestIdleCallback || ( ( cb ) => setTimeout( cb, 100 ) );
|
||||||
|
|
||||||
const getProductById = ( cartState: Cart | undefined, productId: number ) => {
|
const getProductById = ( cartState: Cart | undefined, productId: number ) => {
|
||||||
return cartState?.items.find( ( item ) => item.id === productId );
|
return cartState?.items.find( ( item ) => item.id === productId );
|
||||||
};
|
};
|
||||||
|
@ -286,7 +290,7 @@ interactivityStore(
|
||||||
|
|
||||||
// This selector triggers a fetch of the Cart data. It is done in a
|
// This selector triggers a fetch of the Cart data. It is done in a
|
||||||
// `requestIdleCallback` to avoid potential performance issues.
|
// `requestIdleCallback` to avoid potential performance issues.
|
||||||
requestIdleCallback( () => {
|
callIdleCallback( () => {
|
||||||
if ( ! selectors.woocommerce.hasCartLoaded( store ) ) {
|
if ( ! selectors.woocommerce.hasCartLoaded( store ) ) {
|
||||||
select( storeKey ).getCartData();
|
select( storeKey ).getCartData();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue