Site editor global styles settings: preserve non-global styles in default site editor settings#74088
Conversation
|
|
||
| const defaultEditorSettings = useMemo( () => { | ||
| // Preserve non-global styles from settings.styles (e.g., editor styles from add_editor_style) | ||
| const nonGlobalStyles = ( settings?.styles ?? [] ).filter( |
There was a problem hiding this comment.
Note there are some concerns with the current architecture.
This PR only proposes to get things working for users while those concerns are addressed. They appear to require non-trivial refactors.
See: #73952 (comment)
There was a problem hiding this comment.
Maybe I should add some comments to explain why we've had to do all this, including the bug fix in #73952
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Size Change: +24 B (0%) Total Size: 2.58 MB
ℹ️ View Unchanged
|
| return { | ||
| ...settings, | ||
| styles: [ | ||
| ...( settings?.defaultEditorStyles ?? [] ), |
There was a problem hiding this comment.
defaultEditorStyles wasn't added to site editor styles in https://github.com/WordPress/gutenberg/pull/72681/files#diff-0be42e7e256be23e22604abd2fafb9fd4b57091ee531ffdf95174cd581bb2dfb
Wondering that was intentional @youknowriad ? Otherwise I can leave it out.
There was a problem hiding this comment.
I'm wondering if the omission was intentional? If memory serves me, adding in defaultEditorStyles is useful for classic themes that haven't thought to include styles that makes working with blocks pleasing. That is to say, when the editor is effectively unstyled. However for block themes / usage in the site editor, I believe we're after more of a 1:1 relationship to what the theme is doing.
So for example, here's my site frontend with my excellent choice of colours:
In the site editor with defaultEditorStyles applied:
And without defaultEditorStyles applied:
The latter appears to be closer to the site frontend, so I'd probably go with including nonGlobalStyles but not including defaultEditorStyles.
What do you think?
There was a problem hiding this comment.
Sounds eminently reasonable. Thanks for digging that up. I wasn't quite sure!
There was a problem hiding this comment.
To close the loop on this, over in the post editor here is the check that uses defaultEditorStyles:
For edit-site I believe we can assume that it always has theme styles as that's what the site editor + global styles is for.
So yeah, I think we're good!
PR #73952 replaced settings.styles with the output of generateGlobalStyles, which only emits styles tagged isGlobalStyles: true, dropping non-global styles such as those registered via add_editor_style(). PR #74088 restored them for the site editor canvas; apply the same isGlobalStyles filter pattern in usePatternSettings so add_editor_style output reappears in pattern previews. Co-authored-by: t-hamano <wildworks@git.wordpress.org> Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: Azragh <azragh@git.wordpress.org>
PR #73952 replaced settings.styles with the output of generateGlobalStyles, which only emits styles tagged isGlobalStyles: true, dropping non-global styles such as those registered via add_editor_style(). PR #74088 restored them for the site editor canvas; apply the same isGlobalStyles filter pattern in usePatternSettings so add_editor_style output reappears in pattern previews. Co-authored-by: t-hamano <wildworks@git.wordpress.org> Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: Azragh <azragh@git.wordpress.org>

What?
Fixes #74081
Follow up to:
Fixes an issue where editor styles added via
add_editor_style()were not being applied in the site editor. The styles were being rendered in the HTML source (in thewp.editSite.initializeEditorvariable) but were not actually applied to the editor canvas.Props to @iamtakashi
Why?
Any non-global styles from
settings.styleswere being discarded when the array was replaced.There's also a missingremoved.defaultEditorStylesthat I'm not sure about. I added it to be consistent with the post editorHow?
Updated
useSpecificEditorSettingsto properly merge all style sources in the order that matches the pattern used in the post editor'suseEditorStyleshook.Testing Instructions
add_editor_style()configured (e.g., theemptythemetest theme)style.css)style.css), add a distinctive style: