Skip to content

Commit

Permalink
Add check for zero to the FocalPointPicker mediaRef which prevents a …
Browse files Browse the repository at this point in the history
…division by zero error when it runs in componentDidMount (#28499)
  • Loading branch information
brentswisher authored Jan 27, 2021
1 parent 1a01bdf commit a596309
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/components/src/focal-point-picker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a596309

Please sign in to comment.