fix: stop layout wobble when the window is resized
Continuous Integration / build_web (push) Failing after 0s
Continuous Integration / build (macos-latest) (push) Skipped
Continuous Integration / build (ubuntu-22.04) (push) Skipped
Continuous Integration / build (windows-11-arm) (push) Skipped
Continuous Integration / build (windows-latest) (push) Skipped
Continuous Integration / nightly_release (push) Skipped

- drop the global transition:all on .scrollY/.library-items (it animated
  width/height during every resize)
- library grid reacts to width changes only, coalesced in rAF, and measures
  offsetTop after the new columns are applied
- header transitions no longer animate layout properties
- disable transitions for 200ms while the OS window is being resized
This commit is contained in:
1xDed committed 2026-11-27 13:39:26 +03:00
1 parent fa29331c1c
commit 08f0ca0df1
4 files changed
+53 -29

No files matched your search

@@ -10,7 +10,7 @@
width: calc(100vw - 4em) !important;
z-index: 10;
padding: 0.25em !important;
transition: all 0.2s ease-in-out;
transition: background-color 0.2s ease-in-out, opacity 0.2s ease-in-out;
html.is-macos & {
// The window has an overlay titlebar: keep controls clear of the traffic lights
+32 -22
View File
@@ -173,32 +173,42 @@ const LibraryItemsGrid = () => {
const [containerWidth, setContainerWidth] = useState<number>(0);
const [scrollMargin, setScrollMargin] = useState<number>(0);
// Determine column count based on container width (simple heuristic)
// Determine column count based on container width (simple heuristic).
// Only width changes matter: observing height caused re-layout feedback while
// the window was resized, and a transitioned header made rows jump.
const [columns, setColumns] = useState(1);
const measureColumns = useCallback(() => {
if (!parentRef.current) return;
const width = parentRef.current.clientWidth;
setContainerWidth(width);
setScrollMargin(parentRef.current.offsetTop);
// Base desired approximate card width (including gap) 180px
const ideal = Math.max(1, Math.floor(width / 180));
setColumns(ideal);
}, []);
useEffect(() => {
measureColumns();
if (!parentRef.current) return;
const element = parentRef.current;
if (!element) return;
let frame = 0;
let lastWidth = -1;
const ro = new ResizeObserver(() => measureColumns());
ro.observe(parentRef.current);
// The audio player and headers can change the page layout; a resize
// listener is enough (observing <body> fires on every image load).
window.addEventListener("resize", measureColumns);
return () => {
ro.disconnect();
window.removeEventListener("resize", measureColumns);
const measure = () => {
frame = 0;
const width = element.clientWidth;
if (Math.abs(width - lastWidth) < 1) return;
lastWidth = width;
setContainerWidth(width);
setColumns(Math.max(1, Math.floor(width / 180)));
// Read offsetTop after the browser has applied the new columns.
frame = requestAnimationFrame(() => {
frame = 0;
setScrollMargin(element.offsetTop);
});
};
}, [measureColumns]);
const schedule = () => {
if (!frame) frame = requestAnimationFrame(measure);
};
schedule();
const observer = new ResizeObserver(schedule);
observer.observe(element);
return () => {
observer.disconnect();
if (frame) cancelAnimationFrame(frame);
};
}, []);
const itemCount = items.data?.Items?.length ?? 0;
// Compute number of virtual rows