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

Site editor: preload post if needed #66631

Merged
merged 3 commits into from
Oct 31, 2024
Merged

Conversation

ellatrix
Copy link
Member

@ellatrix ellatrix commented Oct 31, 2024

What?

Whenever one directly accesses a page in the site editor, preload the page. This is a blocking request: the editor will not load without it.

In the post editor, we already do this: https://github.com/WordPress/wordpress-develop/blob/1508e5bf0fa3ad2d001de08eab4dee49985bb322/src/wp-admin/edit-form-blocks.php#L52

Why?

Users might directly access the page editor in the Site Editor.
Also, this is one of the metrics we track directly. We actually do not track Site Editor load performance for the front-page (the initial Site Editor page).

How?

Preload it.

Testing Instructions

  • Go to the Site Editor > Pages > edit a page (url should be something like /wp-admin/site-editor.php?postType=page&postId=<ID>&canvas=edit. Open the network tab. Reload the editor. Observe that the REST request for the page is gone.

Testing Instructions for Keyboard

Screenshots or screencast

@ellatrix ellatrix added the [Type] Performance Related to performance efforts label Oct 31, 2024
Copy link

github-actions bot commented Oct 31, 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.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: ellatrix <[email protected]>
Co-authored-by: ntsekouras <[email protected]>

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

@@ -10,6 +10,10 @@
*/
function gutenberg_block_editor_preload_paths_6_8( $paths, $context ) {
if ( 'core/edit-site' === $context->name ) {
if ( ! empty( $_GET['postId'] ) ) {
$paths[] = add_query_arg( 'context', 'edit', rest_get_route_for_post( $_GET['postId'] ) );
Copy link
Contributor

Choose a reason for hiding this comment

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

So this will preload any entity (template, post, etc..)?

Copy link
Contributor

Choose a reason for hiding this comment

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

By quickly testing it, probably not for templates.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a great question! Actually postId for templates can be a string instead of a number, so for templates rest_get_route_for_post will indeed return an empty string. I added a guard against that in 0601aec.

Copy link
Contributor

@ntsekouras ntsekouras left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@ellatrix ellatrix enabled auto-merge (squash) October 31, 2024 16:44
@ellatrix ellatrix merged commit 3b9bb77 into trunk Oct 31, 2024
66 checks passed
@ellatrix ellatrix deleted the add/site-editor-preload-post branch October 31, 2024 16:55
@github-actions github-actions bot added this to the Gutenberg 19.7 milestone Oct 31, 2024
karthick-murugan pushed a commit to karthick-murugan/gutenberg that referenced this pull request Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Performance Related to performance efforts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants