diff --git a/packages/components/pagination/__tests__/pagination.test.tsx b/packages/components/pagination/__tests__/pagination.test.tsx index 9f1f08e2df..5de6f4578b 100644 --- a/packages/components/pagination/__tests__/pagination.test.tsx +++ b/packages/components/pagination/__tests__/pagination.test.tsx @@ -81,6 +81,8 @@ describe("Pagination", () => { }); it("the pagination cursor should not have data-moving attribute before intersection", () => { + const originalIntersectionObserver = window.IntersectionObserver; + // save callback and options to later emulate intersection event let intersectCallback: IntersectionObserverCallback | undefined; let intersectOptions: IntersectionObserverInit | undefined; @@ -148,5 +150,7 @@ describe("Pagination", () => { // on rerender, the cursor should have the data-moving attribute expect(cursor).toHaveAttribute("data-moving"); + + window.IntersectionObserver = originalIntersectionObserver; }); }); diff --git a/packages/components/pagination/src/use-pagination.ts b/packages/components/pagination/src/use-pagination.ts index 5ec7948497..97808fae92 100644 --- a/packages/components/pagination/src/use-pagination.ts +++ b/packages/components/pagination/src/use-pagination.ts @@ -283,7 +283,9 @@ export function usePagination(originalProps: UsePaginationProps) { const [setRef, isVisible] = useIntersectionObserver(); useEffect(() => { - setRef(domRef.current); + if (domRef.current) { + setRef(domRef.current); + } }, [domRef.current]); const activePageRef = useRef(activePage);