Fix bump in specificity for layout styles in non-iframed editor #7145
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.




Trac ticket: https://core.trac.wordpress.org/ticket/61829
Github PR: WordPress/gutenberg#64076
Backports the changes from WordPress/gutenberg#64076
What?
Fixes the issue mentioned in WordPress/gutenberg#53468 (comment) to restore theme.json spacing rules taking precedence over the implicit spacing rules in a non-iframed editor.
How?
In
trunkthe code generates a selector like.is-layout-flow > *(specificity 0,1,0) which is fine normally. When in a non-iframed editor, thetransformStylesfunction prefixes selectors with.editor-styles-wrapperto scope them to the editor canvas, so it becomes.editor-styles-wrapper .is-layout-flow > *(specificity 0,2,0), a bump in specificity that causes the precedence of styles to change.In this PR I've changed the selector to
:root :where(.is-layout-flow) > *(still specificity 0,1,0).transformStyleshandles 'root' selectors a little differently, it'll instead replace the:rootpart so it becomes.editor-styles-wrapper where(.is-layout-flow) > *(keeping the specificity at 0,1,0).The other layout selector that this affects is the
:first-child:last-childselectors that are responsible for resetting margin at the start and end of a block list. They traditionally have a 0,2,0 specificity so that they can override both the above rule and any rules in the theme.json. Those selectors are also maintained at 0,2,0 with this change, they become something like:root :where(.is-layout-flow) > :first-child.Here's a list of selectors that will be updated (according to our php tests)
Testing Instructions
styles.blocks):4remtop/bottom margin.Also worth checking out
trunkand comparing the styles. You should see that in trunk the iframed editor looks correct, but when you activate custom fields the non-iframed editor styles are broken.Screenshots or screencast
Before
After
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.