From a95ade252374981f6eb88edb0e0f5a2f9b9ea42e Mon Sep 17 00:00:00 2001 From: Brent Swisher Date: Wed, 27 Jan 2021 14:54:50 -0500 Subject: [PATCH] Add check for zero to the FocalPointPicker mediaRef which prevents a division by zero error when it runs in componentDidMount (#28499) --- packages/components/src/focal-point-picker/index.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/components/src/focal-point-picker/index.js b/packages/components/src/focal-point-picker/index.js index 6213e79dd19456..174fde67c75367 100644 --- a/packages/components/src/focal-point-picker/index.js +++ b/packages/components/src/focal-point-picker/index.js @@ -89,10 +89,19 @@ export class FocalPointPicker extends Component { return bounds; } + // Prevent division by zero when updateBounds runs in componentDidMount + if ( + this.mediaRef.current.clientWidth === 0 || + this.mediaRef.current.clientHeight === 0 + ) { + return bounds; + } + const dimensions = { width: this.mediaRef.current.clientWidth, height: this.mediaRef.current.clientHeight, }; + const pickerDimensions = this.pickerDimensions(); const widthRatio = pickerDimensions.width / dimensions.width;