Skip to content

Commit 177339c

Browse files
authored
fix(ResizablePanel): requestIdleCallback replacement (#668)
1 parent 963587f commit 177339c

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

.changeset/popular-trees-melt.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cube-dev/ui-kit": patch
3+
---
4+
5+
Fix issue that throws an error if ResizablePanel is used in Safari.

src/components/layout/ResizablePanel.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import { useResizeObserver } from '@react-aria/utils';
2-
import { ForwardedRef, forwardRef, useEffect, useMemo, useState } from 'react';
2+
import {
3+
ForwardedRef,
4+
forwardRef,
5+
useEffect,
6+
useMemo,
7+
useRef,
8+
useState,
9+
} from 'react';
310
import { useHover, useMove } from 'react-aria';
411

512
import { useDebouncedValue, useEvent } from '../../_internal/hooks';
@@ -214,6 +221,7 @@ function ResizablePanel(
214221
props: CubeResizablePanelProps,
215222
ref: ForwardedRef<HTMLDivElement>,
216223
) {
224+
const timerRef = useRef<ReturnType<typeof setTimeout>>();
217225
const isControllable = typeof props.size === 'number';
218226
const {
219227
isDisabled,
@@ -329,7 +337,13 @@ function ResizablePanel(
329337
}, [visualSize, isDragging]);
330338

331339
useEffect(() => {
332-
requestIdleCallback(notifyChange);
340+
timerRef.current = setTimeout(notifyChange, 500);
341+
342+
return () => {
343+
if (timerRef.current) {
344+
clearTimeout(timerRef.current);
345+
}
346+
};
333347
}, [providedSize]);
334348

335349
const mods = useMemo(() => {

0 commit comments

Comments
 (0)