Skip to content
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

PostCSS usage is broken in editor if Yoast is used. #120

Closed
tcmulder opened this issue Sep 9, 2024 · 3 comments
Closed

PostCSS usage is broken in editor if Yoast is used. #120

tcmulder opened this issue Sep 9, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@tcmulder
Copy link
Owner

tcmulder commented Sep 9, 2024

When Yoast is active, the editor canvas iframe falls back to the old div.editor-styles-wrapper version that attempts to scope all CSS. When using PostCSS, currently nested CSS gets output as nested CSS, since it has support in all modern major browsers; but, in the old div.editor-styles-wrapper version of the editor, this causes parent CSS to have .editor-styles-wrapper nested between them and their children.

Issue opened here for that issue.

Solutions:

  1. I'm going to try just using scss for now, as it seems to perform all the nesting translations back to an older version of CSS.
  2. Maybe I could get PostCSS to disable nesting. Wasn't finding very clear documentation on how to opt out of common CSS functionality.
  3. I can enqueue the CSS in the enqueue_block_editor_assets hook, but things break outside the editor: nothing is scoped in the old div.editor-styles-wrapper version of the editor.
@tcmulder tcmulder converted this from a draft issue Sep 9, 2024
@tcmulder
Copy link
Owner Author

Here's the ticket in Yoast: Yoast/wordpress-seo#20535

@tcmulder tcmulder added the bug Something isn't working label Sep 14, 2024
@tcmulder
Copy link
Owner Author

Maybe take a look at build tool for: https://github.com/WebDevStudios/wds-bt

@tcmulder
Copy link
Owner Author

As an example for testing, add the following to the playground:

<!-- wp:group {"className":"group-1","layout":{"type":"constrained"}} -->
<div class="wp-block-group group-1"><!-- wp:group {"className":"group-2","layout":{"type":"constrained"}} -->
<div class="wp-block-group group-2"><!-- wp:group {"className":"group-3","layout":{"type":"constrained"}} -->
<div class="wp-block-group group-3"><!-- wp:paragraph {"align":"center"} -->
<p class="has-text-align-center">...</p>
<!-- /wp:paragraph --></div>
<!-- /wp:group --></div>
<!-- /wp:group --></div>
<!-- /wp:group -->

Then in an editor-facing stylesheet (like wp-editor.css), this will work:

.group-1 {
	outline: 1px solid red;
}
.group-1 .group-2 {
	outline: 1px solid blue;
}
.group-1 .group-2 .group-3 {
	outline: 1px solid green;
}
``

but this does not:

.group-1 {
outline: 1px solid red;
.group-2 {
outline: 1px solid blue;
.group-3 {
outline: 1px solid green;
}
}
}


that's because it becomes:

.editor-styles-wrapper .group-1 {
outline:1px solid red;
.editor-styles-wrapper .group-2 {
outline:1px solid blue;
.editor-styles-wrapper .group-3 {
outline:1px solid green
}
}
}

Since nesting is supported in browsers now, it works fine if you disable Yoast (or anything else that'd force a reversion—I read somewhere the presence of any outcated block.json version could do it).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Development

No branches or pull requests

1 participant