Skip to content

Site Editor: preload initial canvas data#78075

Open
chubes4 wants to merge 9 commits into
WordPress:trunkfrom
chubes4:fix/site-editor-preload-canvas-data
Open

Site Editor: preload initial canvas data#78075
chubes4 wants to merge 9 commits into
WordPress:trunkfrom
chubes4:fix/site-editor-preload-canvas-data

Conversation

@chubes4
Copy link
Copy Markdown
Contributor

@chubes4 chubes4 commented May 8, 2026

What?

Preloads initial Site Editor canvas data that can be predicted server-side for the initial route/template:

  • referenced template part records from the resolved initial template
  • post collection requests only when the resolved template contains a Query Loop
  • static front page record/template/type requests when show_on_front=page
  • public taxonomies used by the Site Editor

Why?

The Site Editor currently preloads broad template collections, but the first canvas render can still issue several individual REST requests after boot.

In environments where each WordPress REST request has meaningful transport/bootstrap overhead, those missed preloads add visible latency before the editor canvas is ready.

This keeps the preload set route-aware instead of preloading every template-dependent resource unconditionally.

Fixes #78074.

How?

The preload logic derives likely template slugs from the standard WordPress template hierarchy:

  • specific page route: page-{post_name}, page
  • root Site Editor: front-page, static-front-page page templates, home, index

It then resolves pattern blocks and walks the selected template blocks to preload only template parts actually referenced by core/template-part. Query Loop post collection preloads are added only when the resolved block tree contains core/query.

For static front pages, the page record, page template lookup, and page type requests are also deterministic server-side, so those are preloaded for the root Site Editor route when show_on_front=page.

Testing Instructions

  • Open the Site Editor.
  • In browser devtools, inspect REST requests during the initial canvas load.
  • Confirm route/template-derived requests are satisfied by preloaded data rather than new network requests.

Evidence

Supporting Homeboy-rigs benchmark scenarios: chubes4/homeboy-rigs#108

Scenario Baseline Candidate Delta REST waterfall
Default TT5 home 1223ms 988ms -235ms / -19.2% 5 -> 0
Static front page 1876ms 874ms -1002ms / -53.4% 4 -> 0
Custom front page without Query Loop 1219ms 904ms -314ms / -25.8% 3 -> 0
Custom front page with Query Loop 1277ms 897ms -380ms / -29.8% 4 -> 0

Additional local checks:

php -l lib/compat/wordpress-7.0/preload.php
git diff --check

Gutenberg CI passes, including PHP coding standards, PHP unit tests, Playwright, and performance tests.

AI assistance

  • AI assistance: Yes
  • Tool(s): OpenCode (openai/gpt-5.5)
  • Used for: Investigating missed preload routes, drafting the route-aware patch, running local validation/benchmarks, and preparing the PR description. Chris remains responsible for review and testing.

@chubes4 chubes4 requested a review from spacedmonkey as a code owner May 8, 2026 00:42
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 8, 2026

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: chubes4 <extrachill@git.wordpress.org>
Co-authored-by: talldan <talldanwp@git.wordpress.org>
Co-authored-by: westonruter <westonruter@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>

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

@westonruter
Copy link
Copy Markdown
Member

westonruter commented May 8, 2026

@chubes4
Copy link
Copy Markdown
Contributor Author

chubes4 commented May 9, 2026

Updated this to make the preload set route/template-aware rather than broad/unconditional.

The implementation now derives likely template slugs from the standard template hierarchy, resolves pattern blocks, and only preloads template parts/query data when present in the resolved initial template. I also added static-front-page coverage for the page record, template lookup, and page type requests, since those are deterministic for show_on_front=page.

Supporting benchmark scenarios are in chubes4/homeboy-rigs#108.

@chubes4
Copy link
Copy Markdown
Contributor Author

chubes4 commented May 11, 2026

Pushed the same follow-up preload additions to the Gutenberg backport.

Backport commit: dd5ed07223

The detailed scenario matrix and route-by-route evidence are in the Core PR comment: WordPress/wordpress-develop#11766 (comment)

Local validation for the changed backport file, lib/compat/wordpress-7.0/preload.php:

  • php -l lib/compat/wordpress-7.0/preload.php
  • ./vendor/bin/phpcs -s --standard=phpcs.xml.dist lib/compat/wordpress-7.0/preload.php
  • homeboy lint --path <gutenberg checkout> --extension nodejs --file lib/compat/wordpress-7.0/preload.php

@chubes4
Copy link
Copy Markdown
Contributor Author

chubes4 commented May 13, 2026

Follow-up from the remaining visible REST rows in DevTools: I dug into the preloading middleware keys and caller stacks to separate missing server declarations from client-side duplicate consumers.

The current preload patch should stay focused on deterministic initial canvas data. The remaining OPTIONS rows are not additional PHP preload paths missing from this PR:

One important diagnostics detail: the visible DevTools URL can include _locale=user after apiFetch default middleware runs, but createPreloadingMiddleware() checks the pre-locale key first. For example, GET /wp/v2/taxonomies?context=view is the correct declaration even though DevTools may show /wp/v2/taxonomies?_locale=user&context=view.

So I think the right split is:

The caller-attribution/probe evidence that led to those two issues is captured in this Homeboy run:

Run ID: 63df7a69-2f6f-4a39-9ee6-1fcf07bd449f
Artifact: /Users/chubes/Developer/_bench-evidence/homeboy-artifacts/63df7a69-2f6f-4a39-9ee6-1fcf07bd449f/8c48727c-0eac-4844-bc4b-c6fe2316c366-result-studio-site-editor-preload-comparison-17100-1778709161659-9azz7zw3074.json

Comment thread lib/compat/wordpress-7.0/preload.php Outdated
*
* @return array Filtered preload paths.
*/
function gutenberg_block_editor_preload_paths_6_9( $paths, $context ) {
Copy link
Copy Markdown
Contributor

@talldan talldan May 14, 2026

Choose a reason for hiding this comment

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

It's odd that this function name was already wrong. 😄

Anyway, WordPress 7.0 is already in the late stages of release and its too late to add an enhancement like this. All of this new preloading code should be in the lib/compat/wordpress-7.1 folder instead (to indicate it's intended to be shipped in the 7.1 release).

There is a README here that explains a bit more - https://github.com/WordPress/gutenberg/blob/trunk/lib/README.md

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moved to lib/compat/wordpress-7.1/preload.php, and moved the backport changelog entry to backport-changelog/7.1 as well. Thanks for the pointer!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") [Type] Performance Related to performance efforts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Site Editor: preload template parts, query posts, and taxonomies used during initial canvas load

4 participants