From 43aece434a75641d98de37c36ed6895948a830d8 Mon Sep 17 00:00:00 2001 From: Mason Simon <86958+masonicboom@users.noreply.github.com> Date: Mon, 1 Aug 2022 20:15:34 -0700 Subject: [PATCH] Fallback for contentBoxSize --- src/hooks/useGridDimensions.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/hooks/useGridDimensions.ts b/src/hooks/useGridDimensions.ts index 749ba42004..5c70c401a2 100644 --- a/src/hooks/useGridDimensions.ts +++ b/src/hooks/useGridDimensions.ts @@ -28,9 +28,17 @@ export function useGridDimensions(): [ setBlockSize(initialHeight); const resizeObserver = new ResizeObserver((entries) => { - const size = entries[0].contentBoxSize[0]; - setInlineSize(handleDevicePixelRatio(size.inlineSize)); - setBlockSize(size.blockSize); + const entry = entries[0]; + if (entry.contentBoxSize) { + const size = entry.contentBoxSize[0]; + setInlineSize(handleDevicePixelRatio(size.inlineSize)); + setBlockSize(size.blockSize); + } else { + // Fallback for browsers that don't support contentBoxSize. + const rect = entry.contentRect; + setInlineSize(handleDevicePixelRatio(rect.width)); + setBlockSize(rect.height); + } }); resizeObserver.observe(gridRef.current!);