diff --git a/docker/frontend/src/Library.tsx b/docker/frontend/src/Library.tsx index 2c6151c..7ff4fa3 100644 --- a/docker/frontend/src/Library.tsx +++ b/docker/frontend/src/Library.tsx @@ -4404,16 +4404,29 @@ function useStripWindow(count: number, on: boolean): { ref: RefObject, on: boolean): number { const [width, setWidth] = useState(0); + // Read off the wall that is up and not off the one this was set up on: the wall + // is what the desk draws, and the phone's shelf stands in its place, so a visit + // that opens on the phone mounts it with no wall to measure — and the width left + // at nought lays every row of the shelf out one pixel wide, which is a wall of + // nothing until something else makes the effect below run again. So it is read + // after every render, the way the window the wall draws is (see `useWallWindow`). + const read = useCallback(() => { + const el = ref.current; + if (!el || !el.clientWidth) return; + setWidth((prev) => (prev === el.clientWidth ? prev : el.clientWidth)); + }, [ref]); + useLayoutEffect(() => { + read(); + }); useLayoutEffect(() => { if (!on) return; + read(); const el = ref.current; if (!el) return; - const read = () => setWidth((prev) => (prev === el.clientWidth ? prev : el.clientWidth)); - read(); const ro = new ResizeObserver(read); ro.observe(el); return () => ro.disconnect(); - }, [ref, on]); + }, [ref, on, read]); return width; }