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

Code quality check for theme.json related APIs #45171

Open
oandregal opened this issue Oct 20, 2022 · 47 comments
Open

Code quality check for theme.json related APIs #45171

oandregal opened this issue Oct 20, 2022 · 47 comments
Labels
[Feature] Block API API that allows to express the block paradigm. Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json Needs Dev Note Requires a developer note for a major WordPress release cycle [Type] Code Quality Issues or PRs that relate to code quality [Type] Tracking Issue Tactical breakdown of efforts across the codebase and/or tied to Overview issues.

Comments

@oandregal
Copy link
Member

oandregal commented Oct 20, 2022

This issue tracks the current state of theme.json related APIs from a quality point of view, so we can bring up, discuss and address the issues.

WordPress 6.2: shipped

Public API:

Performance:

  • wp_theme_has_theme_json: cache output #45543
  • wp_get_global_settings: cache output #45372 #45971 #45969
  • wp_get_global_stylesheet: migrate from transient to object cache #45679
  • wp_get_global_styles_svg_filters : migrate from transient to object cache #47460 (done in core as the function was removed from Gutenberg)
  • While initially the cache was implemented as persistent across requests for the above methods, concerns were brought up to make it non-persistent and keep testing: #46150

Sync WordPress core <=> Gutenberg:

WordPress 6.3: shipped

Public API

WordPress 6.4: ongoing

Performance:

Public API

Next

Algorithm:

Public API:

  • Make sure all current uses cases of WP_Theme_JSON or WP_Theme_JSON_Resolver are covered by the addition of public methods.
  • Collocate customTemplates and templateAreas metadata with the actual data they represent (templates and template parts provided by the theme as HTML) and remove them from theme.json. #42732 In testing #38984 we ran into an issue with valid HTML comments that don't belong to a block #47212
  • Deprecate/Remove the wp_theme_json_get_style_nodes filter #45172 Filters, together with methods or the theme.json datum, are all part of the public API. We should aim to not expose private implementation details in the public API that prevent us from evolving it.
  • wp_get_global_styles: resolver the reference to the value #49715

Performance

@oandregal oandregal added [Type] Code Quality Issues or PRs that relate to code quality Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json labels Oct 20, 2022
@oandregal oandregal added the [Status] In Progress Tracking issues with work in progress label Oct 20, 2022
@oandregal
Copy link
Member Author

Added a section on experimental API that covers __experimentalSelector, __experimentalDuotone, and __experimentalStyle.

@oandregal oandregal added [Feature] Block API API that allows to express the block paradigm. and removed [Status] In Progress Tracking issues with work in progress labels Oct 21, 2022
@oandregal
Copy link
Member Author

#45168 is ready for review.

@oandregal
Copy link
Member Author

Added a section about performance.

@bph bph added the Needs Dev Note Requires a developer note for a major WordPress release cycle label Oct 28, 2022
@bph
Copy link
Contributor

bph commented Oct 28, 2022

Added the 'needs-dev-note` to this tracking issue, to make sure we cover all relevant changes for the WordPress 6.2 release.

@spacedmonkey
Copy link
Member

Related: https://core.trac.wordpress.org/ticket/56945 . CC @felixarntz

@spacedmonkey
Copy link
Member

Key goals of this refactor.

  • Do no run logic on themes that do not support theme.json ( have this file ).
  • Only run the logic once.
  • Add set of developer focus functions that stop them from running code again.
  • Add unit tests.
  • Make code standard with rest of core.
  • Make code easier to test.

@oandregal
Copy link
Member Author

oandregal commented Nov 3, 2022

Key goals of this refactor.

Hey @spacedmonkey your comment may induce people to think this is about a refactor, that code does not have unit test, etc.
That's not true.

The issue description should be clear enough, though reiterating never hurts for expectations to be clear for everyone. This is about coordinating work among the dozens of people working on this area by highlighting actionable issues that will have an impact on user experience and/or code longevity.

@oandregal
Copy link
Member Author

WordPress/wordpress-develop#3556 backports to core the wp_theme_has_theme_json method.

@spacedmonkey
Copy link
Member

Hey @spacedmonkey your comment may induce people to think this is about a refactor, that code does not have unit test, etc. That's not true.

Confused by this comment. I am just expanding on all this work should include refactoring to improve code quality and testability. A goal we should always keep in mind for any change to code.

@spacedmonkey
Copy link
Member

Seems like a duplicate: https://core.trac.wordpress.org/ticket/56974 . CC @aristath

@felixarntz
Copy link
Member

@oandregal Most of this issue appears to cover general code quality, however in the description you also mention performance. Would you like to use this issue as a "tracker" / "overview" issue for performance-related enhancements/fixes as well? If so, potentially we should add WordPress/wordpress-develop#3536 (it's a core PR, but may affect Gutenberg as well).

On that note, to be fully transparent here, I'd love to have some guidance for whether something like the above should rather be opened as a Gutenberg PR or core PR in the first place :)

@oandregal
Copy link
Member Author

Created a section for ongoing 6.3 work.

@jsnajdr
Copy link
Member

jsnajdr commented May 4, 2023

Looking at the three wp_get_global_styles issues, they all want to resolve something, or convert it to a "canonical" value, so maybe the best API is not to create separate wp_get_global_styles_resolve_x functions, but to add an options parameter:

wp_get_global_styles( $path, $context, $options )

where the options is an object with fields like resolve_refs, resolve_css_vars etc.

With the "resolve internal CSS var format to standard" and "resolve refs" options, it seems to me they should be resolved by default. Only the "resolve CSS variables into real values" should 100% be an option.

@oandregal
Copy link
Member Author

With the "resolve internal CSS var format to standard" and "resolve refs" options, it seems to me they should be resolved by default. Only the "resolve CSS variables into real values" should 100% be an option.

Agreed with the "internal CSS var", it should always be resolved: this is the easiest and @samnajian is looking into that.

Also agreed on "resolve CSS variables" being not the default behavior. It's only a few setups (different rendering pipelines such as mobile, mails, RSS feed) that would need this one.

I'm not sure about the "resolve refs": as far as my understanding goes, this aims to "declare links" between different style tokens. It may or may not be important for consumers to know those links exist, depending on what they want to do. See conversation at #49715 (comment)

@oandregal
Copy link
Member Author

Relevant thread for the conversation about "transforming/resolving" references and variables in style values https://github.com/WordPress/gutenberg/pull/50484/files#r1192502874

@spacedmonkey
Copy link
Member

This PR is still awaiting review - #45831

There is also WordPress/wordpress-develop#3860 to look at as well.

@dd32
Copy link
Member

dd32 commented Jun 19, 2023

Syncing my comment from https://core.trac.wordpress.org/ticket/58460 over here:

The name wp_get_remote_theme_patterns() feels a bit close to the wp_remote_*() and wp_safe_remote_*() methods to me. The inclusion of remote when it's not actually performing a remote-request seems weird too (I get that it's to say "This returns something that needs to be fetched remotely")

I would suggest that something along the lines of wp_theme_required_patterns() or ...pattern_slugs() is maybe a little more understandable as to what it means? ie. wp_ (it's a WP function) theme_ (It's related to the themes component) required_ (It might not be required, and rather suggested?) pattern_slugs() what's being queried for.

Looking at the rest of this PR, wp_get_... works as the next component is wp_get_global_..., but for wp_get_remote_theme_patterns() I still feel like the above comments make sense.

@oandregal
Copy link
Member Author

Looking at the rest of this PR, wp_get_... works as the next component is wp_get_global_..., but for wp_get_remote_theme_patterns() I still feel like the above comments make sense.

I've prepared WordPress/wordpress-develop#4640 to follow-up on this.

@oandregal
Copy link
Member Author

PR for adding wp_get_theme_template_part_metadata WordPress/wordpress-develop#4971

@oandregal
Copy link
Member Author

I've also updated the issue description with what we shipped in 6.3 and ongoing work for 6.4.

@felixarntz
Copy link
Member

@oandregal Just checking in here for whether the issue description is still accurate? Is there any other work related to this that you intend to get into 6.4? Happy to help where I can!

@oandregal
Copy link
Member Author

oandregal commented Sep 18, 2023

Just checking in here for whether the issue description is still accurate? Is there any other work related to this that you intend to get into 6.4? Happy to help where I can!

@felixarntz yeah, it is. The two opened PRs related to performance are in draft at the moment, I don't think I'll be able to get them ready on time before beta. I'd like to revisit this work for the next cycles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block API API that allows to express the block paradigm. Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json Needs Dev Note Requires a developer note for a major WordPress release cycle [Type] Code Quality Issues or PRs that relate to code quality [Type] Tracking Issue Tactical breakdown of efforts across the codebase and/or tied to Overview issues.
Projects
None yet
Development

No branches or pull requests

8 participants