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

Prevent styles from being added in the site editor #2542

Closed
wants to merge 4 commits into from
Closed

Prevent styles from being added in the site editor #2542

wants to merge 4 commits into from

Conversation

oandregal
Copy link
Member

@oandregal oandregal commented Apr 8, 2022

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 at settings.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:

Captura de ecrã de 2022-04-12 14-28-20

And after this PR:

Captura de ecrã de 2022-04-12 14-25-46

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.

We need to do two orthogonal things:

- Be able to tell which are block styles and which are preset styles:
  the later should still be loaded when the user disables the "theme styles".

- Be able to tell which styles come from "theme.json" and which don't:
  so we can overwrite the former in the site editor, for example.
@oandregal oandregal marked this pull request as ready for review April 13, 2022 09:45
@jorgefilipecosta
Copy link
Member

Committed at 2c2b5d0.

@oandregal oandregal deleted the fix/do-not-add-global-styles-in-site-editor branch April 19, 2022 08:06
@WordPress WordPress deleted a comment from jorgefilipecosta Apr 19, 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
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants