From 2aa3e4106c5192ae1d9662e6647a046e315c8a58 Mon Sep 17 00:00:00 2001 From: 1xDed Date: Fri, 27 Nov 2026 13:40:41 +0300 Subject: [PATCH] fix: repack the library grid only after resize settles Recomputing columns on every pixel of a window drag made cards jump between layouts. Debounce width changes by 120ms. --- src/components/libraryItemsGrid/index.tsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) 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); }; }, []);