diff --git a/src/components/libraryItemsGrid/index.tsx b/src/components/libraryItemsGrid/index.tsx index e7b1f1b..8bdfab1 100644 --- a/src/components/libraryItemsGrid/index.tsx +++ b/src/components/libraryItemsGrid/index.tsx @@ -181,10 +181,11 @@ const LibraryItemsGrid = () => { const element = parentRef.current; if (!element) return; let frame = 0; + let timer: ReturnType | undefined; let lastWidth = -1; - const measure = () => { - frame = 0; + const apply = () => { + timer = undefined; const width = element.clientWidth; if (Math.abs(width - lastWidth) < 1) return; lastWidth = width; @@ -198,14 +199,18 @@ const LibraryItemsGrid = () => { }; const schedule = () => { - if (!frame) frame = requestAnimationFrame(measure); + // While the user drags the window edge, don't reflow the whole grid + // on every pixel; repack once the width has been stable briefly. + if (timer) clearTimeout(timer); + timer = setTimeout(apply, 120); }; - schedule(); + apply(); const observer = new ResizeObserver(schedule); observer.observe(element); return () => { observer.disconnect(); + if (timer) clearTimeout(timer); if (frame) cancelAnimationFrame(frame); }; }, []);