Skip to content

Commit d7939cf

Browse files
authored
fix(ResizablePanel): drift in controllable state (#657)
1 parent 6fee0ae commit d7939cf

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

.changeset/gold-flies-flow.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 drift in Resizable Panel in controllable state.

src/components/layout/ResizablePanel.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ function ResizablePanel(
301301
},
302302
});
303303

304-
// Since we sync provided size and the local one in two ways
304+
// Since we sync provided size and the local one in two ways,
305305
// we need a way to prevent infinite loop in some cases.
306306
// We will run this in setTimeout and make sure it will get the most recent state.
307307
const notifyChange = useEvent(() => {
@@ -329,7 +329,7 @@ function ResizablePanel(
329329
}, [visualSize, isDragging]);
330330

331331
useEffect(() => {
332-
setTimeout(notifyChange);
332+
requestIdleCallback(notifyChange);
333333
}, [providedSize]);
334334

335335
const mods = useMemo(() => {
@@ -355,9 +355,9 @@ function ResizablePanel(
355355
}
356356
{...mergeProps(restProps, {
357357
style: {
358-
// We set a current size further via width/min-width/max-width styles to respect size boundaries
358+
// We set the current size further via width/min-width/max-width styles to respect size boundaries
359359
'--size': `${size}px`,
360-
// We use a separate visual size to paint the handler for smoother experience
360+
// We use a separate visual size to paint the handler for a smoother experience
361361
'--visual-size': `${visualSize}px`,
362362
'--min-size': typeof minSize === 'number' ? `${minSize}px` : minSize,
363363
'--max-size': typeof maxSize === 'number' ? `${maxSize}px` : maxSize,

0 commit comments

Comments
 (0)