Add REST preload paths for query loop blocks in the editor#14
Open
roborourke wants to merge 1 commit into
Open
Add REST preload paths for query loop blocks in the editor#14roborourke wants to merge 1 commit into
roborourke wants to merge 1 commit into
Conversation
Hooks block_editor_rest_api_preload_paths to parse the post's block content for core/query blocks and derive the exact REST URL that core/post-template's getEntityRecords() will request, so the apiFetch preloading middleware can serve the first-paint posts response from cache without an HTTP round-trip. Mirrors the query-arg shape from packages/block-library/src/post-template/ edit.js: offset (always passed, default 0), order/orderby, per_page when set, author, search, and sticky/ignore_sticky. Skips loops with taxQuery (taxonomy rest_base mapping complexity) and excludeDisplayed (depends on runtime render order). Capped at 10 loops per post to avoid payload bloat. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Playwright test resultsDetails
Failed testschromium › preload-paths.spec.js › Query Loop REST Preloading › should preload /wp/v2/posts REST path for query loop blocks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
block_editor_rest_api_preload_pathsto parsepost_contentforcore/queryblocks withparse_blocks()core/post-template'sgetEntityRecords()will request (mirrorsper_page/offset/order/orderby/stickyshape from Gutenberg'spost-template/edit.js)taxQuery(taxonomyrest_basemapping is non-trivial for v1) andexcludeDisplayed(depends on runtime render order)Context
This is Track B in a two-track exploration of reducing editor API load on magazine-style pages with many Query Loop blocks. See also PR #11 (Track A: explicit Preview/Edit toolbar toggle using ServerSideRender).
How to choose between the two approaches after both land:
If preload gives 80%+ of the win with no UX surface area, ship this PR and close #11.
Test plan
npm run wp-env start, runnpm run build/wp/v2/postsrequests on editor load should be 0 (served from preload)wp-api-fetchinline script with preloaded REST responsesnpm run test:e2e— all existing tests pass + newpreload-paths.spec.jstest🤖 Generated with Claude Code