-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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 Editor 's shadow DOM of edited page: <body> misses many classes upon which CSS selectors may depend: such as page-template-*, page-id-*, post-type-* , etc #51353
Comments
I can confirm this, I was working on a theme that was relying on the .error-404 class to style that page and saw that the classes are missing in the editor. That leads to inconsistencies between editor and frontend for themes that rely on the classes. |
I think this is a duplicate of #17854? |
Let's close this out as it seems to be a duplicate of the above items. If that's incorrect, please comment back on here and I'll reopen! |
@spencerfinnell looking that over, I think the current issue reported there is covered by work around having style partials as mentioned here: #39281 Does that match your understanding? |
#13339 refers to the client-side implementation of https://developer.wordpress.org/reference/functions/body_class/ which does not exist as far as I am aware. |
Problem
In the shadow DOM of the Block Editor the
<body>
element misses many classes which may be legitimately used as a CSS selector. Such as those which are specific for a content-type (post vs. page) or template or certain page-IDs.Proposed Fix / Improvement
Include the relevant classes like in the
<body>
of the Frontend output in the Block Editor shadow DOM too, except of course those which are Frontend runtime specific (such as Logged-In, or those coming from plugins and their dynamic runtime state).Reproduction
My CSS selector in my enqueued global.css file
Which in the enqueued representation gets:
✅ In the Frontend this works:
❌ In the Block Editor this has no effect.
After debugging I found out why:
Output in Frontend:
<body class="page-template-default page page-id-1571 page-child parent-pageid-24 logged-in admin-bar no-customize-support wp-custom-logo wp-embed-responsive gspbody gspb-bodyfront mega-menu-max-mega-menu-1 mega-menu-max-mega-menu-2" style="position: relative;">
Shadow DOM in the Block Editor:
<body class="block-editor-iframe__body editor-styles-wrapper post-type-page admin-color-fresh wp-embed-responsive" tabindex="0" contenteditable="false">
Realization
A lot of classes are missing in the Block Editor environmnet, which should be there, because it's legit to use them as CSS selectors:
Some classes are only mode/runtime relevant, and are ok to be left out in the body of the Block Editor Shadow DOM:
But it is very legit to have CSS styles specifically for:
These should be present in the Block Editor too!
Environment
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
No
The text was updated successfully, but these errors were encountered: