WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.46k stars 4.18k forks source link

Image block not resizing correctly #37374

Open ice9js opened 2 years ago

ice9js commented 2 years ago

Description

I noticed the image block breaks when you attempt to resize it if Insert from URL feature was used and the image is using left, right or center align.
The image appears fine in the editor but you'll notice negative values for width and height in the sidebar - once you reload the editor or go into the preview the image will be sized differently.

Step-by-step reproduction instructions

  1. In the post editor, add a regular image block (core/image).
  2. Use Insert from URL option in the image placeholder to insert an image from a URL.
  3. Select Align Left, Align Right or Align Center from the alignment options in the toolbar.
  4. Resize the image by grabbing one of the handles at the edge and moving it.
  5. Watch width and height settings in the sidebar while you're resizing it.

Note: I noticed that if I start resizing an image as soon as I add it and then change block alignment, the bug no longer occurs.

Screenshots, screen recording, code snippet

Screen Shot 2021-12-14 at 3 09 20 PM

Environment info

I've noticed this issue on WordPress 5.9-beta2-52363 as well as Gutenberg 12.1.0.

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

glendaviesnz commented 2 years ago

I wasn't able to replicate this on the latest GB trunk:

resize

I wonder if it was fixed by #37210, @ice9js is it possible for you to retest in an environment with a build of the latest GB trunk?

MadtownLems commented 2 years ago

@glendaviesnz - Are you able to re-test with one minor tweak?

I am experiencing the same negative width/height when an aligned image is resized SMALLER. (It actually doesn't matter if it's from URL or media library). But a key part of the problem is that the FIRST drag-to-resize needs to be smaller, not larger.

When I align an image, then drag it smaller, I get negative a negative width and height.

MadtownLems commented 2 years ago

I have confirmed this bug still exists on 5.9 (no Gutenberg plugin).

Simply: Add an Image Block Select an Image Align it Right Drag to Resize it Smaller. Notice that you now have negative image dimensions set.

Mamaduka commented 2 years ago

Here are my results. WP 5.9 without Gutenberg.

https://user-images.githubusercontent.com/240569/152385824-e14c857e-c963-444f-9469-003224d98775.mp4

MadtownLems commented 2 years ago

And here's my screencast. ( also WP 5.9 without gutenberg 🤔)

https://user-images.githubusercontent.com/945157/152389881-0eab562e-5567-4141-a798-68baf0c07dc7.mp4

glendaviesnz commented 2 years ago

Thanks for the extra detail @MadtownLems, I was able to replicate this on GB trunk if I make the image smaller first. Interesting that it is fine for you @Mamaduka, I wonder if it is something to do with the original dimensions/aspect ratio of the image as well? I will try and take a closer look at it today.

glendaviesnz commented 2 years ago

I haven't had any luck tracking this down yet. For some reason, the ResizableBox component in some instances returns a negative value, even though the minHeight and minWidth values are positive values.

Mamaduka commented 2 years ago

Thanks for the confirmations, @glendaviesnz.

I think narrowing down the "requirements" to constantly reproduce the issue will be very helpful for tracking this down

glendaviesnz commented 2 years ago

I think narrowing down the "requirements" to constantly reproduce the issue will be very helpful for tracking this down

Yeh, it mostly did it for me, but sometimes didn't, and wasn't able to isolate what was the difference. I will take another look at it next week if someone else doesn't get to it.

MadtownLems commented 1 year ago

FWIW, I am no longer experiencing this particular image block sizing problem on 6.2

perkele1989 commented 1 year ago

I am experiencing this issue on 6.2

Using an SVG, editing the header of a site using the theme Launchify. When inspecting in HTML, it gets negative values. Results in a huge file. Cant change it to positive values in HTML because block editor says it got unexpected stuff.