-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Block: remove inner div wrapper #19593
Conversation
c8374b3
to
b2220b9
Compare
Impressive work. These last few wrappers are hard to remove, though! A lot of blocks, if not core blocks, target Let me zoom back a little bit, and bear with me as it might get long. I'm trying to understand the consequences myself as well. It gets to the question of: what is a block? The correct answer is, it's anything you as a developer decide is a block. It does not just map to HTML. Take the Paragraph block, for instance — right now it maps one to one: a single
However you could create a block that simply output this:
This would be a silly block, but it's possible! Now let's say I was a developer that wanted to affect every single block with my plugin. For example maybe I wanted to add a global option to adjust the size of the spacing between each block. I cannot predict the markup of every block out there, so I look for a generic HTML element present in the markup that I know will be there. For now, and I've seen this in a few 3rd party blocks, this has been Could I target Don't get me wrong — for every wrapping element you remove, we make the future development experience better for ever new block created. But for one, I think we'll always need at least one wrapping element to define the outermost boundary of the block. And this PR, specifically, will need to be tested with quite a few plugins to see if/how it breaks things. For example, I know that it will break https://wordpress.org/plugins/layout-grid/. I'm not sure it will work, but can we move the |
@jasmussen Yes, we could add And yes, you're right. We'll always need the wrapping element. It was never my intention to remove the outer wrapper for all block. Maybe I miscommunicated that. It's my intention to make leaving away the outer wrapper opt-in by the block. This could be useful in the list and table block for example. |
I think that's worth a shot. If you want to try, I have a couple of plugins I can test! |
Added the |
With the restoration of the data-block attribute, so far my test results with a few plugins including the aformentioned layout-grid and coblocks, the results are promising. Things seem to work right! I think it would be good if more people could test this with a variety of content and plugins, though — the change is as big as it is important. Good for it to receive lots of eyes. |
Thanks for testing @jasmussen! I'll let it sit a bit longer. |
Considering we needed to change several of the core blocks to accommodate this change, would it be reasonable to expect this might be the case for other third-party custom block implementations? I would think it should fall within allowable changes, but wonder if it would be something to consider for a Dev Note. (Aside: I was hoping to use wpdirectory.net to try to search for some potential plugin/theme conflicts, but it doesn't appear to be working at the moment) |
@aduth Yes, I've already added the "Needs Dev Note" label. I think there can be tiny visual changes for more complex blocks, but nothing more. Blocks will continue to function normally without errors. This |
Ah! I missed that, sorry. I'd agree with you on your general point. The potential conflicts here are more likely of the sort where the theme is anticipating some rigid DOM hierarchy, which this change would appear to mitigate to a degree. |
62a9ecf
to
4f80081
Compare
I really appreciate these "lightening the DOM" PRs. Thanks Ella! I tested this out with most blocks using the Twenty Twenty theme and didn't see any visual problems. 👍 |
Let's do it. This allows us to move forward with further improvements. I don't see any issues with removing it. At most a plugin or theme will have to make a small correction. |
Awesome work as always. |
I am as excited for the lean markup we have now, and what it enables for simpler block dev as I can be. I do think we should perhaps make the dev note bold, because it will break some blocks. It's worth it, and it's stellar work, but it's a biggish change! |
@jasmussen What do you mean with making it bold? I'm all for more notes and more communication about it. |
Oh I mean it literally. Make the text in the dev note bold! :) |
That change is nice to see, the selectors were ridiculously long. If I understand correctly, with #19010 as well, a nested block selector changed from:
to:
Could this be simplified further? Is
Could it be 0?
|
@ktmn There's definitely plans for further simplification, but I couldn't do everything in a single release. |
In WordPress/gutenberg#19593 a wrapper `div` was removed, which had a `position` value of `relative`. Our overlay `div` to prevent the iframe from being interacted with, relies on a parent element being `positino: relative`. This is still the case when the block is in the main flow/centre aligned, but when the block is left or right aligned, it can't be selected, and clicks are handled by the iframe. I think the above PR is in Gutenberg 7.3 and higher, so this problem can be replicated with the plugin installed, and therefore also on WPCOM.
In WordPress/gutenberg#19593 a wrapper `div` was removed, which had a `position` value of `relative`. Our overlay `div` to prevent the iframe from being interacted with, relies on a parent element being `positino: relative`. This is still the case when the block is in the main flow/centre aligned, but when the block is left or right aligned, it can't be selected, and clicks are handled by the iframe.
#14820) In WordPress/gutenberg#19593 a wrapper `div` was removed, which had a `position` value of `relative`. Our overlay `div` to prevent the iframe from being interacted with, relies on a parent element being `positino: relative`. This is still the case when the block is in the main flow/centre aligned, but when the block is left or right aligned, it can't be selected, and clicks are handled by the iframe.
Description
This PR removes the inner div wrapper of blocks. This wrapper was previously used to contain the block content so event listeners on this wrapper would ignore events from the block controls. Since the controls are now removed from the block DOM, this wrapper is no longer needed.
Looks like this improves performance by another 3%.
Additionally, this is part of an effort to lighten the block DOM, with the ultimate goal to make it easier for theme author to style the editor content and to enable a semantic relationship between a block and inner blocks.
How has this been tested?
Block alignments, blocks with inner blocks, and multi-selection.
Screenshots
Types of changes
Checklist: