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

Preload: fix multiple regressions around global styles #7661

Closed
wants to merge 4 commits into from

Conversation

ellatrix
Copy link
Member

@ellatrix ellatrix commented Oct 28, 2024

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.

Copy link

github-actions bot commented Oct 28, 2024

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.

Copy link

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.

Copy link

@apermo apermo left a comment

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.

👍

src/wp-admin/edit-form-blocks.php Outdated Show resolved Hide resolved
@ramonjd
Copy link
Member

ramonjd commented Oct 28, 2024

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"

Copy link
Member

@ramonjd ramonjd left a comment

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
Contributor

Was this regression introduced during the 6.7 cycle?

@ramonjd
Copy link
Member

ramonjd commented Oct 29, 2024

Was this regression introduced during the 6.7 cycle?

Yes. Not too late to update?

@peterwilsoncc
Copy link
Contributor

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

'/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
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
Member

Choose a reason for hiding this comment

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

@ramonjd
Copy link
Member

ramonjd commented Oct 29, 2024

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

@ramonjd
Copy link
Member

ramonjd commented Oct 29, 2024

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

@peterwilsoncc
Copy link
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
Copy link
Member

ramonjd commented Oct 29, 2024

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
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants