Prevent styles from being added in the site editor #2542
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Trac ticket: https://core.trac.wordpress.org/ticket/55567
What?
This PR fixes a bug by whiche the global styles are enqueued twice in the site editor.
Why?
The site editor, unlike other editors, generates the styles coming from global styles (presets, styles) dynamically in the client. This is because the user can modify any value that we need to consolidate (merge core, theme, and user style preferences). We don't want to have the global styles twice, as it introduces subtle bugs.
How?
This PR tags styles to be removed with the
isGlobalStyles: true
flag.The styles sent by the server to the client end up in the
block-editor
store, to be found atsettings.styles
. By doing this, we leverage the existing mechanism in the site editor to recalculate the global styles upon user changes.These are the styles before this PR:
And after this PR:
Note how the first 3 styles are no longer in the store.
Testing Instructions
Use this branch and verify that the block editor store has only 3 styles after this PR (would have 6 before).
Do some random manual test: add some block and set some preset values (colors, font sizes) as block styles and make sure they still work. Set some global styles and verify they work.