mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-04-05 22:57:40 +03:00
Merge pull request #53 from ibs0d/claude/fix-grid-layout-height-p9ZWo
fix: use callback ref to measure container width after skeleton unmounts
This commit is contained in:
commit
52f78c9de9
@ -327,16 +327,15 @@ export default function DraggableGridLayout({
|
||||
calculateRemValue();
|
||||
}, []);
|
||||
|
||||
const gridContainerRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
const [containerWidth, setContainerWidth] = useState(0);
|
||||
const [containerHeight, setContainerHeight] = useState(0);
|
||||
const roRef = useRef<ResizeObserver | null>(null);
|
||||
|
||||
// useLayoutEffect reads ref.current after commit (refs are set before layout
|
||||
// effects run), so this reliably fires before the first paint regardless of
|
||||
// whether SWR triggers subsequent re-renders or not.
|
||||
useLayoutEffect(() => {
|
||||
const el = gridContainerRef.current;
|
||||
// Callback ref fires whenever the element mounts/unmounts, so containerWidth
|
||||
// is always set immediately when the grid div first appears (after skeleton).
|
||||
const gridContainerRef = useCallback((el: HTMLDivElement | null) => {
|
||||
roRef.current?.disconnect();
|
||||
roRef.current = null;
|
||||
if (!el) return;
|
||||
setContainerWidth(el.clientWidth);
|
||||
setContainerHeight(el.clientHeight);
|
||||
@ -345,7 +344,7 @@ export default function DraggableGridLayout({
|
||||
setContainerHeight(entry.contentRect.height);
|
||||
});
|
||||
ro.observe(el);
|
||||
return () => ro.disconnect();
|
||||
roRef.current = ro;
|
||||
}, []);
|
||||
|
||||
const scrollBarWidth = useMemo(() => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user