-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add check for zero to the FocalPointPicker mediaRef which prevents a division by zero error #28499
Conversation
…division by zero error when it runs in componentDidMount
Size Change: +21 B (0%) Total Size: 1.37 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested and this fixes #28487.
Failing media modal related end-to-end tests are a known issue in Core and unrelated to this PR, see https://core.trac.wordpress.org/ticket/50025#comment:23. |
…division by zero error when it runs in componentDidMount (#28499)
Cherry-picked to |
If I now have a block cover with background image, fixed attachment and gradient overlay combined, the image disapears in the editor when I change alignment settings or reload the page (inline styles gone). Also when duplicating the block with ctrl + shift + D. Edit: Doesn't even need a gradient to reproduce. If I toggle the "attachment fixed" switch it's there again. |
Description
Fixes #28487. In #28096, because updateBounds was added to
componentDidMount
, it runs after themediaRef
exists, but before it has received the width/height or the image. This results in a division by 0 which errors out and sets the left bound of the focal point picker to beNaN
. This caused the focal point picker to not work in the horizontal direction as well as throwing a console error.Specifically, these lines were erroring because dimensions.width and dimensions.height were both set to 0
How has this been tested?
Open a new post and insert a cover block
Select the cover block
See that the focal point picker can now be moved horizontally and there is no console error
Types of changes
Bug fix (non-breaking change which fixes an issue)
Checklist: