Skip to content

Revisions: Skip rendered fields in REST API responses#76347

Merged
ellatrix merged 4 commits intotrunkfrom
fix/revisions-api-skip-rendered-fields
Mar 12, 2026
Merged

Revisions: Skip rendered fields in REST API responses#76347
ellatrix merged 4 commits intotrunkfrom
fix/revisions-api-skip-rendered-fields

Conversation

@ellatrix
Copy link
Copy Markdown
Member

@ellatrix ellatrix commented Mar 10, 2026

What?

Optimizes the revisions REST API endpoint and client-side queries to avoid fetching expensive rendered fields (content.rendered, title.rendered, excerpt.rendered) when only raw data is needed.

Why?

The speedup is significant: from 5-6 seconds to 50-60 ms for 20 revisions!

The REST API _fields documentation states that nested fields are supported using dot notation. However, the core WP_REST_Revisions_Controller uses in_array() which doesn't match nested keys like content.raw — so clients either get both raw and rendered, or neither.

Several other controllers already use rest_is_field_included() for raw/rendered sub-fields:

How?

PHP: Override revisions controller (WordPress 7.0 compat)

  • Adds Gutenberg_REST_Revisions_Controller extending WP_REST_Revisions_Controller
  • Replaces in_array() checks with rest_is_field_included() for content, title, excerpt, and guid fields
  • Registers the override via register_post_type_args filter, following the same pattern as the autosaves controller override

JS: Request only needed sub-fields

  • Updates getCurrentRevision, getPreviousRevision, the revisions slider, useEntityProp, and restoreRevision to use _fields=id,date,author,meta,title.raw,excerpt.raw,content.raw
  • All callers use the same query, ensuring a single shared API request

Testing Instructions

  1. Open a post with multiple revisions
  2. Open the revisions panel in the document sidebar
  3. Open browser DevTools Network tab
  4. Verify the revisions API request includes _fields=id%2Cdate%2Cauthor%2Cmeta%2Ctitle.raw%2Cexcerpt.raw%2Ccontent.raw
  5. Verify the response contains content.raw but NOT content.rendered
  6. Verify revision diffing works correctly (scrub through revisions, compare content)
  7. Verify restoring a revision still works

Testing Instructions for Keyboard

  1. Open a post with revisions using keyboard navigation
  2. Tab to the revisions slider in the document sidebar
  3. Use arrow keys to scrub through revisions
  4. Verify revision content updates correctly

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

Labels

Backported to WP Core Pull request that has been successfully merged into WP Core [Package] Core data /packages/core-data [Package] Editor /packages/editor [Type] Performance Related to performance efforts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants