-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Fix bump in specificity for layout styles in non-iframed editor #7145
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN:
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for putting this together @talldan 👍
I've tested it in the post editor, following the instructions on this PR and the additional steps outlined over on the Gutenberg PR in WordPress/gutenberg#64076 (comment).
✅ Block-level margin styles in global styles overrides base spacing styles
✅ Block-level margin styles in global styles overrides block level spacing in global styles (e.g. Group block set to 0 block spacing will be overridden by paragraphs within the Group if paragraphs have margin set)
✅ Block instance level block spacing overrides global styles margin rules
✅ Block instance level margins override block instance level block spacing
✅ Block spacing for buttons, social icons, row, stack, and grid all appear to be working
I didn't spot any issues. This LGTM 🚢
Before (iframed) | Before (non-iframed) |
---|---|
After (iframed) | After (non-iframed) |
---|---|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- ✅ Resolves the issue - See my test report.
- ✅ Correctly generates the expected CSS - See my findings report.
- ✅ Changes match changes in Gutenberg PR.
LGTM and ready for commit.
Committed to |
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
trunk
the code generates a selector like.is-layout-flow > *
(specificity 0,1,0) which is fine normally. When in a non-iframed editor, thetransformStyles
function prefixes selectors with.editor-styles-wrapper
to 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).transformStyles
handles 'root' selectors a little differently, it'll instead replace the:root
part 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-child
selectors 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
):4rem
top/bottom margin.Also worth checking out
trunk
and 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.