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

Update format used by font resolver #50499

Closed
wants to merge 3 commits into from

Conversation

oandregal
Copy link
Member

@oandregal oandregal commented May 10, 2023

Follow-up to #50297 and #50366

What?

Fixes two issues:

Why?

#50366 updated gutenberg_get_global_styles so that the custom format var:preset|... is never returned to consumers. Just before it was merged, a PR for the font resolver landed at #50297 that makes use of that format. Hence, when 50366 landed, it broke the font resolver.

Investigating this issue uncovered a bug in how the user-provided fonts are detected. See #50297 (comment)

How?

  • Update the font resolver to use the regular format.
  • Update the font resolver to query for user data explicitly, instead of trying to infer it based on whether the font is using var:preset|... format that any origin can use.

Testing Instructions

Make sure automated test pass.

See manual test instructions at #50297

@oandregal oandregal self-assigned this May 10, 2023
@oandregal oandregal added [Type] Bug An existing feature does not function as intended Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Status] In Progress Tracking issues with work in progress labels May 10, 2023
@oandregal
Copy link
Member Author

oandregal commented May 10, 2023

Current status of the PR: it returns all the expected results defined by the tests plus the system-font (which it should not according to the tests).

@oandregal
Copy link
Member Author

Current status of the PR: it returns all the expected results defined by the tests plus the system-font (which it should not according to the tests).

This issue uncovered a bug in the way the fonts API enqueues user-provided fonts. See https://github.com/WordPress/gutenberg/pull/50297/files#r1189573512

It relied on the font using the var:preset|... format to decide whether it was user-provided or not. Anyone can use the var:... format, the tests just happened not to.

@github-actions
Copy link

github-actions bot commented May 10, 2023

Flaky tests detected in 0211bb9.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4935454675
📝 Reported issues:

@oandregal oandregal marked this pull request as ready for review May 10, 2023 09:36
$global_styles = wp_get_global_styles();
$user_selected_fonts = static::get_user_selected_fonts( $global_styles );
$user_selected_fonts = array();
$user_global_styles = WP_Theme_JSON_Resolver_Gutenberg::get_user_data()->get_raw_data();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this avoid the cache we introduced?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has the same performance impact than using wp_get_global_styles. That function has not a cache of their own: both approaches rely on the resolver cache.

@hellofromtonya
Copy link
Contributor

user-provided font

What does this mean?

The Resolver's intent is to detect and then automatically enqueued fonts that a user "selects" for global usage via the Site Editor > Styles > Typography UI. All of the theme defined fonts (via theme.json file) are already registered and enqueued for global usage. But fonts registered via plugin (i.e. not in the theme's theme.json file) that are selected for global usage by a user need to be detected for auto enqueuing.

I assume user "provided" is different than user "selected".

@oandregal can you share more about the intent of this PR and the distinction between user "provided" and user "selected"?

And do you foresee system fonts as having property definitions that require a @font-face to be generated and printed by the Fonts API?

Copy link
Contributor

@hellofromtonya hellofromtonya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm blocking this PR until further discussion happens about its intent and what issues it resolves. Why? The PR is taking a different approach to identify all user "provided" fonts vs user "selected" fonts that are not in a theme's theme.json file.

@oandregal
Copy link
Member Author

oandregal commented May 10, 2023

There are few things here:

  1. PHP unit tests are failing
  2. There is a bug in the existing resolver code [Fonts API] Automatically enqueue user-selected fonts #50297 (comment)
  3. There's confusion in the font resolver about how to work with theme.json data.

I'm interested in shipping a fix for 1 ASAP as it's blocking development. If necessary, I'm open to revert #50366 but that is not the issue. 2 is also fixed by this PR.

3 requires a larger conversation and I need to look at the fonts code to understand how it is organized and ways forward. The TLDR is this: wp_get_global_styles or any other theme.json API doesn't give you data for a "single" origin (for example, only the data for "user"). It actually merges all the data together. The fonts resolver API PR circumvented this by checking for the var:preset|... format, expecting it only to come from the user data. That format can come from any other origin (default, theme, etc.). I created a test case to reproduce the bug at #50501

Does this help?

@hellofromtonya
Copy link
Contributor

More discussion is needed around how to identify which fonts a user selected in the Site Editor > Global Styles > Typography UI. As PR #50297 is currently causing failed tests that is blocking development on other PRs, I'll revert that PR, reopen its enhancement issue, and then reopen a PR with the same code for further discussion.

@oandregal
Copy link
Member Author

Closing this in favor of #50512

@oandregal oandregal closed this May 10, 2023
@oandregal oandregal deleted the update/font-resolver-use-regular-css-format branch May 10, 2023 12:43
hellofromtonya added a commit that referenced this pull request May 10, 2023
@priethor priethor removed the [Status] In Progress Tracking issues with work in progress label May 11, 2023
anton-vlasenko pushed a commit that referenced this pull request May 12, 2023
hellofromtonya added a commit that referenced this pull request May 22, 2023
* Adds user-select fonts enqueuer.

* Auto queue before printing

* Always set $handles to false when empty

When invoked as a hooked callback, it receives an empty string.
Empty is the same as false.

* Use WP_Theme_JSON_Resolver_Gutenberg::get_user_data().

From PR #50499.
Props @oandregal.

* Adds print tests. Moves datasets to trait.
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] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants