Directory

Allow customization of block preview height · Issue #60990 · WordPress/gutenberg · GitHub
Skip to content
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

Allow customization of block preview height #60990

Closed
jefferyto opened this issue Apr 23, 2024 · 11 comments · Fixed by #61397
Closed

Allow customization of block preview height #60990

jefferyto opened this issue Apr 23, 2024 · 11 comments · Fixed by #61397
Assignees
Labels
[Package] Block editor /packages/block-editor [Status] In Progress Tracking issues with work in progress [Type] Regression Related to a regression in the latest release

Comments

@jefferyto
Copy link

What problem does this address?

Before WordPress 6.5, the block preview height was not fixed, instead adapting to the height of the preview content. After 6.5, the block preview height appears to be fixed to 150px, I believe as a result of #59112.

150px is not tall enough for many (most?) blocks, but more importantly, any single fixed height will not work for all blocks.

What is your proposed solution?

Support either one or (ideally) both:

  • Allow the block developer to explicitly indicate the ideal preview height, similar to setting viewportWidth.
  • Allow the preview to adapt to the height of the preview content.
@jefferyto jefferyto added the [Type] Enhancement A suggestion for improvement. label Apr 23, 2024
@annezazu
Copy link
Contributor

cc @t-hamano as you worked on that prior PR!

@t-hamano
Copy link
Contributor

Thanks for the report.

#59112 is meant to fix bugs that were originally not working as expected. Additionally, the height applied to the preview is a minimum value rather than a fixed value.

Are there any steps to reproduce this problem?

@jefferyto
Copy link
Author

Additionally, the height applied to the preview is a minimum value rather than a fixed value.

It does not appear to be applied as a minimum value.

Are there any steps to reproduce this problem?

  1. Add a new post or page.
  2. Open the block selector.
  3. Hover over a block to see the preview.

I am using Firefox 125.0.2 on Ubuntu 23.10.

WordPress 6.4.2:

6 4-1
6 4-2
6 4-3
6 4-4
6 4-5

WordPress 6.5.2:

6 5-1
6 5-2
6 5-3
6 5-4
6 5-5

@t-hamano
Copy link
Contributor

Thanks for the reply.

You seem to be testing on Ubuntu, but can you check if it reproduces on other OS or browsers?

I couldn't reproduce it in my environment. I hope others will test this issue as well.

Environment Info

  • OS: Windows 11
  • Browser: Firefox 125.0.2 (64-bit)

image

@t-hamano t-hamano added [Type] Bug An existing feature does not function as intended Needs Testing Needs further testing to be confirmed. and removed [Type] Enhancement A suggestion for improvement. labels Apr 24, 2024
@jefferyto
Copy link
Author

I traced the issue to having this in my theme's editor stylesheet:

body {
    height: 100%;
}

(More specifically, this was set for the front-end and included in the editor stylesheet.)

I assume the preview component is setting the iframe height based on the height of the body element. I suggest setting height: auto inline to override any theme CSS.

@t-hamano
Copy link
Contributor

I traced the issue to having this in my theme's editor stylesheet:

Could you tell me how this style is enqueued? If we can reproduce this problem in our environment, we may be able to decide whether to solve this problem with Gutenberg.

@jefferyto
Copy link
Author

Could you tell me how this style is enqueued?

My theme is a classic theme, the editor stylesheet is enqueued with:

function after_setup_theme_editor_style() {
	add_editor_style();
}
add_action( 'after_setup_theme', 'after_setup_theme_editor_style' );

The stylesheets are written with Sass, and the editor stylesheet includes most of the styles from the front-end stylesheet as the theme also has some custom blocks.

@t-hamano
Copy link
Contributor

t-hamano commented May 1, 2024

I tested it with Twenty Twenty-One, but I can't reproduce it. (Regardless of whether Gutenberrg plugin is enabled)

I added body { height: 100% } here.

As the screenshot shows, the body element inside the preview iframe has height:auto overriding 100%.

height-100

@jefferyto
Copy link
Author

jefferyto commented May 1, 2024

For me the body { height: 100%; } in my editor stylesheet is transformed to .editor-styles-wrapper { height: 100%; } and so overrides body { height: auto; }. All other body references in the stylesheet are transformed to .editor-styles-wrapper when applied in the editor.

Edit: I made the same edit to Twenty Twenty-One and I see the issue (and body styles are still transformed to .editor-styles-wrapper).

@t-hamano
Copy link
Contributor

t-hamano commented May 2, 2024

I was able to reproduce this problem.

In order to reproduce this issue, the block editor must be non-iframed. That is, if you have a custom field enabled or a block registered with apiVersion 2.

However, this issue should not be caused by #59112. This is because #59112 makes changes to the edit-site package, but this issue can be reproduced using the post editor.

@t-hamano t-hamano added [Type] Regression Related to a regression in the latest release [Package] Block editor /packages/block-editor and removed [Type] Bug An existing feature does not function as intended Needs Testing Needs further testing to be confirmed. labels May 2, 2024
@t-hamano
Copy link
Contributor

t-hamano commented May 5, 2024

When I went back through the commit history, I found that this problem occurred in #57810.

I also provide detailed reproduction steps.

Steps

  • Enable Twenty Twenty-One and add height: 100%; here. This stylesheet is loaded into the editor via add_editor_style().
  • Enable custom fields in the editor. This will make the editor no longer an iframe.
  • Open the main inserter, open the Patterns tab, and select one of the categories.

✅ Before #57810 is merged (commit hash: f6d29bd)

The height:100% defined in the theme is applied to the body element. This value will be overwritten by auto.

before

❌ Right after #57810 is merged (commit hash: 45eb9a5)

The height:100% defined in the theme is applied via the .editor-styles-wrapper selector. This value is not overwritten.

after

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Block editor /packages/block-editor [Status] In Progress Tracking issues with work in progress [Type] Regression Related to a regression in the latest release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants