-
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
Differing CSS specificity between Non-Iframed Editor and Front end #63925
Comments
Thanks for reporting this. I think it's a similar issue to the one mentioned here: #53468 (comment) Though the selectors you mention are different. Something to note is that the iframe is there for a reason, it prevents outside styles leaking in and the inside styles leaking out. Without it some extra specificity may naturally be required and the That said, it shouldn't change from WordPress release to release unless there's a good reason, so we can investigate if there's been a change, and if so try to fix things in another WordPress minor release. I also wonder if it's worth looking at making the |
But why is the non-iframed editor there? By default I have the iframed editor, but when I install a plugin that adds metaboxes it switches to non-iframed. But then when I switch to Tablet/Mobile preview it's iframed again and works perfectly. So why doesn't the editor just switch to an iframed "Desktop" preview right off the bat so I never have to even think about the non-iframed editor? |
It's a good point! I was curious about it too. I had a look through some past issues and the discussion here outlines the reasoning - #48286 (comment) TLDR: There are no big metabox compatibility issues, it's more about finding a UI that isn't clunky as the default experience. A solution has been attempted in #59242, but there's a lot of discussion there and a blocking review. When using third party blocks you may also have some that are using an |
Ignore that - I accidentally test with the Gutenberg plugin active on my 6.5 environment. I can confirm it was a regression in 6.6, so hopefully it's something we can put a fix out for in a minor WordPress release (6.6.2 or 6.6.3). FWIW, it seems like there's more momentum on solving the custom fields issue - #64247. |
#64266 is also reporting the same issue, but with the Post Title block. I've closed that one as a duplicate. |
Is this issue going to be fixed in 6.6.2, or is it scheduled for 6.7? |
I am hoping this is addressed before 6.7. As noted, enabling plugins that add meta boxes (such ACF or Yoast) disables the iFramed editor for hybrid themes and puts us back into the situation where new CSS specificity is applying block spacing margins to things it should not be. |
It's unclear as of yet, the first thing is that a fix still needs to be worked on for the issue. It's one of the next things on my list unless someone is able to pick it up before me. 🙏 |
Here's a breakdown of the problem and some possible fixes. Sorry for the long comment, but hopefully it makes it clear exactly what has happened and provides some options: 6.5The theme.json block styles previously output a very simple selector like this (specificity 0,1,0): .wp-block-heading This beat element styles. Those would be output like this when in an iframe (0,0,1): h1, h2, h3, h4, h5, h6 When non-iframed, the selectors are prefixed (using postcss-prefixwrap) to scope the styles. This increased the specificity of the theme.json block styles (0,2,0): .editor-visual-styles .wp-block-heading It still beats the similarly prefixed element styles when there's no iframe (0,1,1): .editor-visual-styles h1,
.editor-visual-styles h2,
.editor-visual-styles h3,
.editor-visual-styles h4,
.editor-visual-styles h5,
.editor-visual-styles h6 6.6In 6.6 iframed editor the block style has changed to this, the same specificity (0,1,0): :root :where(.wp-block-heading) In the non-iframed editor, problems start to happen. The CSS prefixer behaves differently for selectors prefixed with .editor-visual-styles :where(.wp-block-heading) Now it stays at 0,1,0. Element styles are prefixed in the same way they were in 6.5 (0,1,1) so the non-iframed element styles now beat the block styles in terms of specificity. Possible fixesChange how root prefixing worksThe main problem to me appears to be how the prefixing works. For some root prefixed selectors it keeps the specificity the same, but for others it increases the specificity and that causes inconsistencies in how styles are applied. We could look at changing how the prefixing works, but that would be quite a big change, and would require a lot of testing. Possibly too big in scope for 6.6.2. If we go this route, an option is to consider changing how root prefixing works so that it also results in a specificity bump (in this example, perhaps generating a selector like Make the prefixing result in no specificity bumpSimilar to the above, another option is to try making the A risk is that styles that aren't supposed to apply to the editor canvas start to take precedence over block/theme styles. Try adjusting the element style selectors like #64076 didIt might be possible to try a similar fix like in #64076. If the element selectors are changed to something like Would love to hear if anyone has more ideas on fixing this. |
Description
With non-iframed block editor, specificity of top-level element selectors are different relative to other selectors. I believe this is due to the
.editor-style-wrapper
prefix.Step-by-step reproduction instructions
Screenshots, screen recording, code snippet
Theme
theme.json
style.css
templates/index.html
<!-- wp:post-content /-->
Observed behavior
✅
core/heading
block styles override top-level elementheading
styles.✅
core/heading
block styles override top-level elementheading
styles.❌ Top-level element
heading
styles overridecore/heading
block styles. Elementheading
styles have specificity (0, 1, 1) whereascore/heading
block styles have (0, 1, 0).Environment info
Please confirm that you have searched existing issues in the repo.
Please confirm that you have tested with all plugins deactivated except Gutenberg.
The text was updated successfully, but these errors were encountered: