Skip to content

Preload: fix multiple regressions around global styles - #7661

Closed
ellatrix wants to merge 4 commits into
WordPress:trunkfrom
ellatrix:fix/global-styles-preload
Closed

Preload: fix multiple regressions around global styles#7661
ellatrix wants to merge 4 commits into
WordPress:trunkfrom
ellatrix:fix/global-styles-preload

Conversation

@ellatrix

@ellatrix ellatrix commented Oct 28, 2024

Copy link
Copy Markdown
Member

A PR to track the backporting of WordPress/gutenberg#66468

This fixes a regression whereby requests to global styles endpoints were not being preloaded, resulting in several requests being fired clientside unnecessarily.

For performance reasons, we should preload the requests so that the data is in the store and ready to use straight away.

The outcome is that the editor loads more quickly.

Testing

Fire up this branch and head to the site editor.

Check that global-styles endpoints aren't fetched client side, but are, rather, preloaded via rest_preload_api_request

Do the same for the post editor.

Trac ticket: https://core.trac.wordpress.org/ticket/62315


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@github-actions

github-actions Bot commented Oct 28, 2024

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props ellatrix, ramonopoly, apermo, peterwilsoncc.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@apermo apermo left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Besides my comment, that I'm unsure about naming of the variable, this looks technically solid and fine.

👍

Comment thread src/wp-admin/edit-form-blocks.php Outdated
Comment thread src/wp-admin/site-editor.php Outdated
Comment thread src/wp-admin/edit-form-blocks.php Outdated
@ramonjd

ramonjd commented Oct 28, 2024

Copy link
Copy Markdown
Member

I tested this using the plugin (to get the js packages) and reverting the PHP changes in WordPress/gutenberg#66468

Looks good in both the site and post editors - the requests cited in WordPress/gutenberg#66468 are now prefetched by rest_preload_api_request

"/wp/v2/global-styles/themes/twentytwentyfive?context=view"
"/wp/v2/global-styles/themes/twentytwentyfive/variations?context=view"
"/wp/v2/global-styles/5"
"/wp/v2/global-styles/5?context=edit"

@ramonjd ramonjd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I added some missing commas, which were crashing things, but LGTM

@peterwilsoncc

Copy link
Copy Markdown
Contributor

Was this regression introduced during the 6.7 cycle?

@ramonjd

ramonjd commented Oct 29, 2024

Copy link
Copy Markdown
Member

Was this regression introduced during the 6.7 cycle?

Yes. Not too late to update?

@peterwilsoncc

Copy link
Copy Markdown
Contributor

@ramonjd in cycle regressions can still be fixed, so it's not too late.

'/wp/v2/global-styles/themes/' . $stylesheet . '/variations?context=view',
'/wp/v2/themes?context=edit&status=active',
array( '/wp/v2/global-styles/' . WP_Theme_JSON_Resolver::get_user_global_styles_post_id(), 'OPTIONS' ),
'/wp/v2/global-styles/' . WP_Theme_JSON_Resolver::get_user_global_styles_post_id() . '?context=edit',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Depending on user capabilities, a different clientside request will fire, e.g.,

✅ user can update global styles: '/wp/v2/global-styles/' . WP_Theme_JSON_Resolver::get_user_global_styles_post_id() . '?context=edit',

🔕 user cannot update global styles: '/wp/v2/global-styles/' . WP_Theme_JSON_Resolver::get_user_global_styles_post_id() . '?context=view',

So at the moment, editors will get a clientside request since '?context=view', isn't preloaded.

I'm wondering if it's worth changing this to "view" context based on caps.

Probably for a follow up, as this already fixes a bunch of unnecessary requests.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@ramonjd

ramonjd commented Oct 29, 2024

Copy link
Copy Markdown
Member

WordPress/gutenberg#66468 has been cherry picked to Gutenberg's wp/6.7 branch

@ramonjd

ramonjd commented Oct 29, 2024

Copy link
Copy Markdown
Member

Do we need a second committer review to get this in the next 6.7 RC?

@peterwilsoncc

Copy link
Copy Markdown
Contributor

@ramonjd The trunk commit can be on your approval, then re-open the trac ticket and add the dev-feedback keyword to put it in the queue for a second committer to review for backport.

@ramonjd

ramonjd commented Oct 29, 2024

Copy link
Copy Markdown
Member

Committed in r59316 / dc4bd050

@ramonjd ramonjd closed this Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

No open projects
Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

4 participants