diff --git a/src/components/libraryHeader/libraryHeader.scss b/src/components/libraryHeader/libraryHeader.scss index d6f7cbc..3a0c657 100644 --- a/src/components/libraryHeader/libraryHeader.scss +++ b/src/components/libraryHeader/libraryHeader.scss @@ -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 diff --git a/src/components/libraryItemsGrid/index.tsx b/src/components/libraryItemsGrid/index.tsx index 86d6132..e7b1f1b 100644 --- a/src/components/libraryItemsGrid/index.tsx +++ b/src/components/libraryItemsGrid/index.tsx @@ -173,32 +173,42 @@ const LibraryItemsGrid = () => { const [containerWidth, setContainerWidth] = useState(0); const [scrollMargin, setScrollMargin] = useState(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 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 diff --git a/src/main.tsx b/src/main.tsx index 68b7c1b..12af062 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -100,6 +100,17 @@ const init = async () => { document.documentElement.classList.add("is-macos"); } + // Layout transitions during a live window resize cause visible wobble + // (headers, cards, MUI components). Disable them until resizing settles. + let resizeTimer: ReturnType | undefined; + window.addEventListener("resize", () => { + document.documentElement.classList.add("is-resizing"); + if (resizeTimer) clearTimeout(resizeTimer); + resizeTimer = setTimeout(() => { + document.documentElement.classList.remove("is-resizing"); + }, 200); + }); + const initialApi = await initializeApi(); ReactDOM.createRoot(document.getElementById("root")!).render( diff --git a/src/styles/global.scss b/src/styles/global.scss index 85804c6..a15e0f3 100644 --- a/src/styles/global.scss +++ b/src/styles/global.scss @@ -36,13 +36,21 @@ html { overscroll-behavior: none; } +// While the OS window is being resized, skip layout transitions so elements +// do not chase the new size frame by frame. +html.is-resizing *, +html.is-resizing *::before, +html.is-resizing *::after { + transition: none !important; +} + body { font-family: "Plus Jakarta Sans Variable",system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; background: $clr-background-default; margin: 0; padding: 0; position: relative; - width: 100vw; + width: 100%; height: 100vh; overflow-x: hidden; overflow-y: auto; @@ -205,11 +213,6 @@ h1 { padding-bottom: 9em !important; } -.library-items, -.scrollY { - transition: all $transition-time-default !important; -} - // Normalize listItemIcons for material symbols .MuiListItemIcon-root { font-size: 24px;