Fix: remove IntersectionObserver shim (https://github.com/woocommerce/woocommerce-blocks/pull/4808)
This commit is contained in:
parent
1bdb9b51c8
commit
0f2c035423
|
@ -2,7 +2,6 @@
|
|||
* External dependencies
|
||||
*/
|
||||
import { useRef, useLayoutEffect, useState } from '@wordpress/element';
|
||||
import { getIntersectionObserver } from '@woocommerce/base-utils';
|
||||
|
||||
/** @typedef {import('react')} React */
|
||||
|
||||
|
@ -50,7 +49,7 @@ export const usePositionRelativeToViewport = () => {
|
|||
] = useState( '' );
|
||||
const referenceElementRef = useRef( null );
|
||||
const intersectionObserver = useRef(
|
||||
getIntersectionObserver(
|
||||
new IntersectionObserver(
|
||||
( entries ) => {
|
||||
if ( entries[ 0 ].isIntersecting ) {
|
||||
setPositionRelativeToViewport( 'visible' );
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
/** @typedef {import('window').IntersectionObserverCallback} IntersectionObserverCallback */
|
||||
|
||||
/**
|
||||
* Util that returns an IntersectionObserver if supported by the browser. If
|
||||
* it's not supported, it returns a shim object with the methods to prevent JS
|
||||
* errors. Notice it's a shim, not a polyfill. If the browser doesn't support
|
||||
* IntersectionObserver, the methods returned by this function will do nothing.
|
||||
*
|
||||
* @param {IntersectionObserverCallback} callback Callback function for the
|
||||
* Intersection Observer.
|
||||
* @param {Object} options Intersection Observer options.
|
||||
* @return {Object|IntersectionObserver} Intersection Observer if available,
|
||||
* otherwise a shim object.
|
||||
*
|
||||
* @todo Remove IntersectionObserver shim when we drop IE11 support.
|
||||
*/
|
||||
export const getIntersectionObserver = ( callback, options ) => {
|
||||
if ( typeof IntersectionObserver !== 'function' ) {
|
||||
return {
|
||||
observe: () => void null,
|
||||
unobserve: () => void null,
|
||||
};
|
||||
}
|
||||
|
||||
return new IntersectionObserver( callback, options );
|
||||
};
|
|
@ -3,7 +3,6 @@ export * from './address';
|
|||
export * from './shipping-rates';
|
||||
export * from './legacy-events';
|
||||
export * from './render-frontend';
|
||||
export * from './get-intersection-observer';
|
||||
export * from './get-valid-block-attributes';
|
||||
export * from './product-data';
|
||||
export * from './derive-selected-shipping-rates';
|
||||
|
|
Loading…
Reference in New Issue