-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
[Fonts API] Relocate which fonts to print into wp_print_fonts() #50151
[Fonts API] Relocate which fonts to print into wp_print_fonts() #50151
Conversation
5663329
to
6ce3620
Compare
1a9ae3f
to
cf9942a
Compare
Now that PR #50225 has been merged into |
This simplifies the code as it removes the need to modify and then reset the `done` and `queue` properties.
cf9942a
to
d95eb1c
Compare
// Print all registered fonts for the iframed editor. | ||
if ( true === $handles ) { | ||
$handles = $registered; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this condition be moved above the if ( empty( $handles ) ) {
check a few lines above? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good observation @aristath! Yes, I agree with you.
In looking further at this area of code, there's a tiny tiny micro-optimization opportunity which will benefit the front-end, i.e. when false
then skip over these decision-making reassignment conditionals as they are unnecessary.
Changes done here fd7ce33
c1a255a
to
338d4aa
Compare
Combines the empty() and true checks into a if/elseif structure. For a tiny micro-optimization, wraps these checks within a not equal to `false`. Why? When using the default (i.e. on the front-end and with classic themes): * Skips running `empty()`. * Skips reassigning `false` to `$handle`. These skips gain a tiny tiny performance boost.
338d4aa
to
fd7ce33
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Printing `$handles` does not work (for some reason that needs to be investigated further). Overwriting the queue and done properties does print and has been working since 6.2 alpha. This commit restores the overwriting properties approach.
@anton-vlasenko thank you for testing. You're right. It does not print within the Site Editor or other block editors (like Posts). Why? How I fixed it: Restoring that logic keeps the PR's scope focused on "relocating" the logic. A follow-up PR can come later for changing the approach to copying registered fonts to Can you re-test please @anton-vlasenko ? |
Flaky tests detected in dfd8657. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4918768728
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've retested this PR after applying the changes in dfd8657, and it worked in my tests. The code makes sense, so I approve this PR.
Thank you for the thorough explanation, @hellofromtonya! |
Thanks for retesting and approving the PR @anton-vlasenko! |
cc: @arthur791004 |
Moves decision-making logic for iframed editor from the compat script-loader files into the Fonts API.
I just cherry-picked this PR to the release/15.7 branch to get it included in the next release: 5682ad4 |
Fixes #50140
What?
Relocates the decision making code about which fonts to print for the iframed editor out of the script-loader and into the
wp_print_fonts()
function.Why?
When in the Site Editor, all registered fonts should be printed for user previewing and selection. Else, all enqueued fonts should be printed. This kind of decision making should be in the Fonts API, rather than externally in the script-loader.
How?
This PR places the decision making logic into
wp_print_fonts()
.How to identify the iframed editor assets function is invoking the printing?
This function needs to know if the request to print is coming from the iframed editor for decision making about which fonts to print. This is done by passing
true
to the first parameter ofwp_prints_fonts()
.Notes:
true
for$handles
is not used byWP_Dependencies
(including inwp_print_styles()
andwp_print_scripts()
. Using it avoids performance hits and BC concerns with the other strategies considered (expand the next section more more details).Strategies considered
Approach 1: Adding a parameter to the function's signature
Pros:
true
.Cons:
wp_print_styles()
andwp_print_scripts()
.Approach 2: Pass true to the first parameter as flag to indicate to populate the iframed editor handles.
Pros:
true
is not used inwp_print_styles()
orwp_print_scripts()
.Cons:
Approach 3: Add or use a hook.
Approach 3.1: Hook into the
'block_editor_settings_all'
to modify the'__unstableResolvedAssets
' setting.In WP Core, the call stack is this:
_wp_get_iframed_editor_assets()
invokes
_wp_get_iframed_editor_assets()
which will invoke
wp_print_fonts()
There is a filter after this code called
'block_editor_settings_all'
.Gutenberg uses this approach to modify the settings for the upcoming release.
Pros:
Cons:
_wp_get_iframed_editor_assets()
, which would make maintaining more complex._wp_get_iframed_editor_assets()
that could require changes withinwp_print_fonts()
of which setting or subsetting to modify. (Conversely if invoking directly within_wp_get_iframed_editor_assets()
all knowledge is contained in one place for the iframed editor assets.)Approach 3.2: Add a hook in
_wp_get_iframed_editor_assets()
.Pros:
Cons:
TODO
Testing Instructions
Visually Test:
Set up on your test site:
Before applying this PR:
wp-fonts-local
<style>
element.After applying this PR:
wp-fonts-local
<style>
element.Running the automated tests
All tests should pass when running the PHPUnit tests: