Skip to content

Commit d926a4f

Browse files
committed
Add null check for getDimensions
1 parent 84cfb60 commit d926a4f

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/utils.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,20 @@ export const getDimensions = (entry: ResizeObserverEntry, box: ResizeObserverBox
105105
// 'content-box' No No Yes
106106
// undefined No No? Yes
107107

108-
if (box === 'border-box') {
108+
const borderBox = entry.borderBoxSize?.[0];
109+
const contentBox = entry.contentBoxSize?.[0];
110+
111+
if (box === 'border-box' && borderBox) {
109112
return {
110-
width: entry.borderBoxSize[0].inlineSize,
111-
height: entry.borderBoxSize[0].blockSize,
113+
width: borderBox.inlineSize,
114+
height: borderBox.blockSize,
112115
};
113116
}
114117

115-
if (box === 'content-box') {
118+
if (box === 'content-box' && contentBox) {
116119
return {
117-
width: entry.contentBoxSize[0].inlineSize,
118-
height: entry.contentBoxSize[0].blockSize,
120+
width: contentBox.inlineSize,
121+
height: contentBox.blockSize,
119122
};
120123
}
121124

0 commit comments

Comments
 (0)