Layouts: Update editor layout definitions to better select the first block #70003
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What?
Closes #69989
This PR fixes the unintentional top margin (
margin-block-start
) on thepost content
block when placed within the template query. (Likely introduced in #66003)Why?
This happens because the following line tries to apply a top margin of
0 px
to the first child.gutenberg/packages/block-editor/src/layouts/definitions.js
Line 103 in 551c62f
The problem occurs when there are multiple
<style>
and<SVG>
elements before the first element within the editor. Refer to the following DOM structure:These elements hold the preview styles related to the
content
block.Ref.
gutenberg/packages/block-library/src/post-content/edit.js
Line 59 in 05f769e
How?
Since all the blocks within the editor have a
.wp-block
class, we can update the selection logic to be:' > :nth-child(1 of .wp-block)'
Because the
.wp-block
class is not present in the front-end and since the problem doesn't occur in there (as the<style>
and<svg>
tags are not rendered within the parent block), I didn't feel the need to update the rules for the corresponding PHP file.Testing Instructions
Click to toggle the code
From
wp-admin
, navigate to Appearance > Editor > Templates > Blog Home.Confirm that the
Post Content
block has no extra margin on top and looks exactly like the front-end.Testing Instructions for Keyboard
Same.
Screenshots