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

Backport: Gutenberg 44731 #3481

Closed
wants to merge 11 commits into from
Closed

Conversation

scruffian
Copy link

This backports WordPress/gutenberg#44731

I couldn't get it to work locally because the CSS file didn't seem to be there, but maybe I'm testing it wrong?

@ockham
Copy link
Contributor

ockham commented Oct 17, 2022

I couldn't get it to work locally because the CSS file didn't seem to be there, but maybe I'm testing it wrong?

I haven't tested it yet, but did you npm i before building to make sure you've got the latest package versions?

@scruffian
Copy link
Author

Yes, but I still didn't see the CSS file...

@ockham
Copy link
Contributor

ockham commented Oct 17, 2022

Hmm, I am getting

  | <br />
-- | --
  | <b>Warning</b>:  file_get_contents(/wp-includes/css/dist/block-library/classic.css): failed to open stream: No such file or directory in <b>/var/www/src/wp-includes/script-loader.php</b> on line <b>3696</b><br />
  | <br />
  | <b>Warning</b>:  Cannot modify header information - headers already sent by (output started at /var/www/src/wp-includes/script-loader.php:3696) in <b>/var/www/src/wp-admin/admin-header.php</b> on line <b>9</b><br />

// only handles external files or theme files.
$editor_settings['styles'][] = array(
'css' => file_get_contents( $classic_theme_styles ),
'__unstableType' => 'theme',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should be core? It's arguably Core that's providing this styling 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc/ @oandregal @jorgefilipecosta for Global Styles expertise 😊

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll tentatively change it to core since IMO it better represents where the styling is coming from.

Since this is targeting classic themes, it shouldn't have any actual implications, since this is for Global Styles -- which are unavailable for Classic Themes.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that's a good idea.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👋 Looked at where __unstableType is used. It's only at https://github.com/WordPress/gutenberg/blob/88a1f7ae18bea3a13f6d1e507e3c25090b76cb08/packages/edit-post/src/editor.js#L165

If I'm reading the original PR correctly, this is used to decide whether to render a particular stylesheet when the user deactivates "theme styles". If the stylesheet needs to be disabled by that check, we should use "theme", otherwise "core" is fine. See check in this screen:

imagem

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These styles are the "default" ones set for buttons by core, they aren't connected to a specific theme, so I think core is correct.

ockham
ockham previously approved these changes Oct 17, 2022
Copy link
Contributor

@ockham ockham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This LGTM and fixes the issue for me:

In the post editor, with Twenty Ten active:

image

@ockham
Copy link
Contributor

ockham commented Oct 17, 2022

Ugh, unit tests are failing because they cannot locate that file:

file_get_contents(/var/www/src/wp-includes/css/dist/block-library/classic.css): failed to open stream: No such file or directory

I'll look into this tomorrow. Not sure if something is off with the way we're building things for unit tests, or if there's another reason 😕

@scruffian
Copy link
Author

We found another bug with the original solution, which I have a fix for here: WordPress/gutenberg#45063

I'll also backport that in this PR

@ockham
Copy link
Contributor

ockham commented Oct 19, 2022

Ugh, unit tests are failing because they cannot locate that file:

file_get_contents(/var/www/src/wp-includes/css/dist/block-library/classic.css): failed to open stream: No such file or directory

I'll look into this tomorrow. Not sure if something is off with the way we're building things for unit tests, or if there's another reason 😕

Some quick thoughts on this:

  • My current working hypothesis is that maybe we're not building @wordpress package JS and CSS before running PHP unit tests.
  • We have other functions (e.g. wp_default_styles) that register styles that might (?) not exist at the time. How do they do it? (Or is it all classic stylesheets are readily available at the time that tests are run?)
  • Are there any helpers we can use instead of file_get_contents that will avoid the "not found" error at test time (via some indirection?)
  • Finally, do we need to mock that file, or file_get_contents when run for that file, or all of wp_add_editor_classic_theme_styles?

@scruffian
Copy link
Author

Would it be simpler to just use a static CSS file?

@ockham
Copy link
Contributor

ockham commented Oct 19, 2022

Would it be simpler to just use a static CSS file?

Probably 🤔 Maybe due to my ignorance -- there might be established patterns to deal with built CSS in a scenario like this, I'm just unaware of it.

Would we lose anything significant if we made it static?

@scruffian
Copy link
Author

Would we lose anything significant if we made it static?

Nothing at all

@scruffian
Copy link
Author

Done in 20fed67, lets hope the tests pass!

@cbravobernal
Copy link
Contributor

cbravobernal commented Oct 19, 2022

Using TwentyTwenty Twelve, it seems that the font color of the buttons is different 😢
The CSS specificity seems to be the same on all themes, I tried with 2010, 2011, 2012, and 2013, so maybe that error is not 100% related to this backport.
Also, the theme CSS file is loading correctly in all of them.

Editor:
Screenshot 2022-10-19 at 14 10 19
Frontend:
Screenshot 2022-10-19 at 14 10 23

@scruffian
Copy link
Author

I added a commit to fix Twenty Twelve

@ockham ockham dismissed their stale review October 19, 2022 15:51

Need to re-review with the latest fixes

Copy link
Contributor

@ockham ockham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @scruffian! LGTM :shipit:

Copy link
Contributor

@audrasjb audrasjb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[committer double signoff]
The changeset looks good to me as well.

Self assigning for commit.

Edit: Not yet. See the comment below.

@audrasjb audrasjb self-assigned this Oct 20, 2022
Copy link
Contributor

@audrasjb audrasjb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I think the PR is missing RTL styles, at least for Twenty Twenty.

@sabernhardt
Copy link

Yes, Twenty Twenty also needs the RTL stylesheet, but block styles would belong in editor-style-block.css instead of classic.

Twenty Twelve does not have an RTL stylesheet for the editor.

@scruffian
Copy link
Author

Yes, Twenty Twenty also needs the RTL stylesheet, but block styles would belong in editor-style-block.css instead of classic.

The styles are already in editor-style-block.css, but the problem is that the editor block styles aren't provided through add_editor_style as they are usually. This means they don't get prefixed with editor-styles-wrapper, so they don't have the same specificity as the ones coming from this new CSS file. An alternative would be to manually add this prefix to the rules inside editor-style-block.css which I am happy to do if you think that approach is better.

@sabernhardt
Copy link

sabernhardt commented Oct 20, 2022

The new inline styles come after editor-style-block.css with equal specificity. If you make the selectors slightly more specific for lines 927-928 and the font size adjustment at lines 1308-1309, that should be enough to correct the original state without changing the theme's Classic Editor stylesheet.

:root .editor-styles-wrapper .wp-block-button__link,
:root .editor-styles-wrapper .wp-block-file__button {

Twenty Twenty does not change text color on hover, but you could add the underline in editor-style-block.css, without :root. (Button block elements are not focusable in the editor.)

.editor-styles-wrapper .wp-block-button__link:hover,
.editor-styles-wrapper .wp-block-file__button:hover {
	text-decoration: underline;
}

@scruffian
Copy link
Author

@sabernhardt thanks that's super helpful. I have updated editor-style-blocks and revert the changes to the classic styles. I also updated the RTL stylesheet. Thanks again for all your help.

Copy link
Contributor

@ockham ockham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I retested Twenty Twenty in Hebrew to verify that RTL styling works ✅

image

I also tested Twenty Ten and Twenty Twelve to verify that button styling still works there ✅

Changes look good to me 👍

@audrasjb
Copy link
Contributor

[committer double signoff]

Yeah thanks for the changes. Looks good to me now 👍

@ockham
Copy link
Contributor

ockham commented Oct 25, 2022

Commit message draft:

Editor: Correctly apply Button block styles for classic themes

In [54358], styling for Button blocks that had been removed from classic themes was reintroduced. However, it was added with a global scope, whereas editor styles are usually added with a `.editor-styles-wrapper` selector, which makes them more specific.

This change modifies the way that classic theme styles are added so that they also get wrapped in an `.editor-styles-wrapper` selector to match specificity.

Furthermore, adjust specificity for some Button block related styling in the editor for the Twenty Twelve and Twenty Twenty themes.

Merges [https://github.com/WordPress/gutenberg/pull/44731 Gutenberg PR 44731] into trunk.

Follow-up to [54358].
Props scruffian, cbravobernal, sabernhardt, audrasjb.
See #56467.

@ockham
Copy link
Contributor

ockham commented Oct 25, 2022

Committed to Core trunk in r54687. Awaiting second approval to backport to the 6.1 branch.

@ockham
Copy link
Contributor

ockham commented Oct 25, 2022

Committed to Core trunk in r54687. Awaiting second approval to backport to the 6.1 branch.

Merged to the 6.1 branch in r54688.

@ockham ockham closed this Oct 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

6 participants