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

Global Styles Framework: Remove the need for GlobalStylesProvider and GlobalStylesContext #67534

Open
youknowriad opened this issue Dec 3, 2024 · 6 comments
Labels
Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Type] Enhancement A suggestion for improvement.

Comments

@youknowriad
Copy link
Contributor

The site editor uses GlobalStylesProvider and GlobalStylesContext to be able to track edits and modifications to global styles and also to make useGlobalStyle and useGlobalSettings hooks work properly.

That API was just an imperfect temporary API and it's not really needed. It's also blocking the possibility of third-party users from accessing global styles and modifying them properly.

Instead of this context and hooks, we should just have getGlobalStyle and getGlobalSetting selectors in core-data directly. I don't think the context is needed anymore.

One existing place where the "context" might still be helpful is the "style variations previews". That said, the need there is very small, we can instead just try to retrieve the values we need directly from the global styles objects (background, fonts...)

cc @WordPress/gutenberg-core

@youknowriad youknowriad added [Type] Enhancement A suggestion for improvement. Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json labels Dec 3, 2024
@ramonjd
Copy link
Member

ramonjd commented Dec 3, 2024

Thanks for the issue. Sounds like a plan.

we should just have getGlobalStyle and getGlobalSetting

What would these return? User/merged theme config??

If "user", should we think about stabilizing experimentals such as __experimentalGetCurrentThemeBaseGlobalStyles?

And then, I'm guessing we'll still need the usual suite of utility methods to accompany the API (assuming it's public for third parties). For example, mergeBaseAndUserConfigs — probably can think of a better name, or model after Theme_JSON_Resolver — or a getMerged selector so consumers can get the site's merged styles/settings.

I might be assuming way too much though 😄

@youknowriad
Copy link
Contributor Author

What would these return? User/merged theme config??

It would depend on the arguments I think (just like the hook)

If "user", should we think about stabilizing experimentals such as __experimentalGetCurrentThemeBaseGlobalStyles?

I would like for this to be considered after we explore saved style variations. Because that id might change over time. So maybe the getGlobalStyle, getGlobalSetting can take an optional "user style id".

And then, I'm guessing we'll still need the usual suite of utility methods to accompany the API (assuming it's public for third parties). For example, mergeBaseAndUserConfigs — probably can think of a better name, or model after Theme_JSON_Resolver — or a getMerged selector so consumers can get the site's merged styles/settings.

Why? get/setGlobalStyle and get/setGlobalSetting should handle all the complexity internally.

We might even start with private selectors first and open them on a second time.

@aaronrobertshaw
Copy link
Contributor

What would these return? User/merged theme config??
...
or model after Theme_JSON_Resolver — or a getMerged selector so consumers can get the site's merged styles/settings.

Having alignment or consistency between the JS side and the theme.json PHP classes would help make working with Global Styles features easier.

@ramonjd
Copy link
Member

ramonjd commented Dec 3, 2024

Why? get/setGlobalStyle and get/setGlobalSetting should handle all the complexity internally.

Because when I read getGlobalStyle and I assume get "user" global styles. "get" base config is, or at least has been, the base theme.json, conceptually speaking.

I agree that its complexity should be hidden from the end consumer, e.g., returning base/user/merged via function arguments. So that's also cool!

@Mamaduka
Copy link
Member

Mamaduka commented Dec 4, 2024

Didn't we initially switch to the context instead of the store for performance reasons? I like the proposed solution, but we should watch out for any progressions.

@youknowriad
Copy link
Contributor Author

Didn't we initially switch to the context instead of the store for performance reasons?

If I'm not wrong context was there from the start, but maybe my memory is failing me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

4 participants