-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Site editor global styles settings: ensure generated global styles are correct in canvas between views #73952
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
base: trunk
Are you sure you want to change the base?
Conversation
- Generate global styles from merged configuration to avoid infinite loops. - Filter out global styles from base settings and merge with generated styles. - Update editor settings to include experimental features from global settings.
- Remove unused import of getBlockTypes. - Simplify global styles generation by excluding block types. - Update base settings to exclude styles and experimental features, generating them from the merged config instead. - Ensure global settings are correctly applied to experimental features.
- Remove unused destructuring of styles and experimental features from settings. - Streamline the process of generating base settings for the site editor.
4e68b99 to
7faea80
Compare
|
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. |
|
This also affects the template previews: Kapture.2025-12-12.at.18.23.19.mp4I ran out of time today to work out if there's a better, more universal fix here. |
| * Exclude styles and __experimentalFeatures from base settings | ||
| * since we're generating fresh ones from the merged config. | ||
| */ | ||
| const { styles, __experimentalFeatures, ...baseSettings } = settings; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This smells a bit. Maybe there's a better way. I ran out of time.
- Import private APIs for global styles management. - Generate global styles from merged configuration to streamline settings. - Update pattern settings to include generated styles and experimental features. - Ensure proper memoization of global styles for performance optimization.
Meh, I just added the same fix. |
| const [ globalStyles, globalSettings ] = useMemo( () => { | ||
| return generateGlobalStyles( mergedConfig, [], { | ||
| disableRootPadding: false, | ||
| } ); | ||
| }, [ mergedConfig ] ); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we could make a hook out of all this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean to share between the two files and any others
|
Size Change: +5.67 kB (+0.22%) Total Size: 2.59 MB
ℹ️ View Unchanged
|
| ...baseSettings, | ||
| styles: [ | ||
| ...settings.styles, | ||
| ...globalStyles, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know the background very well, but the PR description mentions that the style settings were moved to the editor package.
I wonder why the styles need to be set here as part of site-editor settings if the editor package is now the source of truth. Should that happen in the editor package instead so that everything is centralized?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with the idea that ultimately, edit-site (and edit-post) should only pass "non global styles" styles to EditorProvider settings. and the Editor package should be able to read the "global styles" styles directly from the API.
I'd go even further and say even "non global styles" styles should ideally cram from a REST API but we don't really have such thing at the moment.
At least it's worth exploring the first option separately to see if it leads better results.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
My goal was to get things working as I suspect there needs to be a larger piece of work here.
I'm not sure we can read straight from the editor store as it is - there are circular dependencies and max depth loops of death since ExperimentalEditorProvider updates editorStore on every settings change.
Here I went with useSpecificEditorSettings() reading only from editSiteStore (no editorStore subscription) for that reason.
But yeah, editor implementations shouldn't pass global styles to the EditorProvider, which means the EditorProvider should be defensive and exclude them from from syncing, since GlobalStylesRenderer handles these if I'm reading things correctly.
The tricky part is that Pattern previews use BlockPreviews, which use the EditorProvider directly, so GlobalStylesRenderer doesn't run. We could create a BlockPreview wrapper in the editor package that includes GlobalStylesRenderer. I'm guessing that's not all that we'll need.
closes #73350
What? How?
Selecting a theme style variation in the Site Editor does not persist between the editor view (
canvas=edit) and the main design view (canvas=view). The styles appear correctly in the editor view but remain stale in the main design view.This PR fixes that by generating global styles directly from the merged config in
useSpecificEditorSettings()instead of reading from either store.Why?
A git bisect led me to this PR:
Before PR #72681:
GlobalStylesRendererupdatededitSiteStoreviaupdateSettings()useSpecificEditorSettings()read fromeditSiteStoreviagetSettings()After PR #72681:
GlobalStylesRenderernow updateseditorStoreviaupdateEditorSettings()useSpecificEditorSettings()still reads fromeditSiteStoreviagetSettings()The entity is saved correctly, but the visual representation in the main design view is stale because it's reading from a different store than the one being updated.
Testing Instructions
Screenshots or screencast
Before
Kapture.2025-12-12.at.16.46.12.mp4
After
Kapture.2025-12-12.at.17.34.28.mp4