Skip to content

Editor: Restore revisions on the server - #82158

Draft
ellatrix wants to merge 6 commits into
trunkfrom
restore-revisions-on-the-server
Draft

ellatrix wants to merge 6 commits into
trunkfrom
restore-revisions-on-the-server

Conversation

@ellatrix

@ellatrix ellatrix commented Aug 28, 2026 •

Copy link
Copy Markdown
Member

What?

Follow up to #78249, which turned Visual Revisions off whenever classic meta boxes are registered, as a way around the restore bug in #78130.

Restoring a revision now happens on the server, and Visual Revisions works again when classic meta boxes are present.

Why?

The editor restored a revision by applying it as edits and saving the post. That has two problems:

  1. The meta boxes overwrote the restore. Their form is submitted after the REST save, carrying whatever the DOM still holds, so meta owned by a classic meta box stayed at the newer value. Even skipping that one submission would not be enough: the fields would still show the old values and put them back on the next save.
  2. Only the fields the editor knows about were restored. Meta that is not exposed to the REST API, and anything plugins restore on wp_restore_post_revision, were left alone. The classic screen restores all of it.

How?

  1. A route to restore a revision. POST /wp/v2/<base>/<id>/revisions/<id>/restore runs wp_restore_post_revision(), the same function revision.php uses. It is added to Gutenberg_REST_Revisions_Controller, and to a new Gutenberg_REST_Template_Revisions_Controller so templates keep working.
  2. The editor loads again after a restore. There is no save, so no meta box submission, and the meta boxes render from PHP with the restored values. The confirmation notice is carried across the load.
  3. disableVisualRevisions is removed, along with the classic screen links on the two revisions controls, the deep link redirect, and the autosave notice branch that read it.
  4. Tests. PHPUnit covers the route, including revisioned meta and permissions. An e2e test fills a classic meta box, saves twice, restores, and checks the field holds its older value.

Testing Instructions

  1. Activate the gutenberg-test-plugin-revisions-meta-box test plugin, or any plugin with a classic meta box that saves meta registered with revisions_enabled.
  2. Create a post, fill the meta box field, and save. Change both the content and the field, then save again.
  3. Open Revisions in the sidebar, slide back to the older revision, and press Restore.
  4. The editor loads again with the older content, the meta box field holds its older value, and a notice confirms which revision was restored.
  5. Save again and confirm the restored value stays.

Also worth checking on a post type without meta boxes, and on a template in the site editor.

Testing Instructions for Keyboard

Tab to Revisions in the sidebar and press Enter, move through the revisions with the slider arrow keys, then tab to Restore and press Enter.

Screenshots or screencast

Before After
The classic revisions screen the Revisions control sends you to today Visual Revisions open on a post that has a classic meta box

After restoring, the classic meta box field holds the restored value:

The editor after a restore, with the meta box field back to its older value and a notice confirming the restore

Use of AI Tools

Authored with Claude Code assistance.

Restoring a revision applied it as edits and saved the post, which left
values that classic meta boxes save through their own form submission at
the newer version, and resubmitted them on the next save. It also only
covered the fields the editor knows about.

Restoring now runs wp_restore_post_revision through a new REST route and
loads the editor again, the way the classic revisions screen works, so
everything a revision holds comes back and the meta boxes render with
the restored values.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Required label: Any label starting with [Type].
  • Labels found: .

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

@github-actions github-actions Bot added [Package] Editor /packages/editor [Package] Edit Post /packages/edit-post [Package] E2E Tests /packages/e2e-tests labels Aug 28, 2026
@github-actions

Copy link
Copy Markdown

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 <ellatrix@git.wordpress.org>

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

@github-actions

Copy link
Copy Markdown

Size Change: -330 B (0%)

Total Size: 7.91 MB

📦 View Changed
Filename Size Change
build/scripts/edit-post/index.min.js 52.4 kB -338 B (-0.64%)
build/scripts/editor/index.min.js 580 kB +8 B (0%)

compressed-size-action

@github-actions

Copy link
Copy Markdown

Flaky tests detected in 96a9518.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/33139968420
📝 Reported tests:

Navigates the items list via UP/DOWN arrow keys in /test/e2e/specs/site-editor/dataviews-list-layout-keyboard.spec.js, passed after 1 failed attempt.
Error: expect(locator).toBeFocused() failed

Locator:  getByLabel('Page Two')
Expected: focused
Received: inactive
Timeout:  5000ms

Call log:
  - Expect "toBeFocused" with timeout 5000ms
  - waiting for getByLabel('Page Two')
    14 × locator resolved to <button type="button" tabindex="-1" aria-pressed="false" id="view-list-0-243-item-wrapper" class="dataviews-view-list__item" aria-labelledby="view-list-0-243-label" aria-describedby="view-list-0-243-description"></button>
       - unexpected value "inactive"

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/site-editor/dataviews-list-layout-keyboard.spec.js:112:49
Should save the changes in /test/e2e/specs/editor/plugins/wp-editor-meta-box.spec.js, passed after 2 failed attempts.
TimeoutError: page.waitForFunction: Timeout 10000ms exceeded.
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/plugins/wp-editor-meta-box.spec.js:34:14
TimeoutError: locator.click: Timeout 10000ms exceeded.
Call log:
  - waiting for locator('role=button[name="Visual"i]')

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/plugins/wp-editor-meta-box.spec.js:33:55

@adamsilverstein

adamsilverstein commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Re-opening this for further consideration. Server based revision restoration offers several advantages over the current approach:

  • Full backwards compatibility with the many large existing plugins that rely on the wp_restore_post_revision action hook firing, see this search and this comment
  • Single revisions restore code path to maintain, vs the two currently divergent code paths
  • Meta revisions and "classic" meta would continue working, see this Issue and this comment from @talldan which led me here
  • We already make a server round trip, so this shouldn't add overhead.

@ellatrix I couldn't tell why this PR was closed, what do you think of pursuing the idea further and replacing the current client side approach for revisions restoration

@adamsilverstein adamsilverstein added the [Type] Bug An existing feature does not function as intended label Nov 28, 2026
Trunk removed the 7.0 compat controllers this branch extended, and the
editor's restore gained a save-first step and an Undo action. The restore
route moves to a standalone 7.3 compat controller, and the editor keeps
those steps while restoring through the route.
@adamsilverstein

Copy link
Copy Markdown
Member

I reopened this and brought it up to date with trunk, it now also covers #85549. The description above still describes the August version.

Claude Code (Fable 5.2) did the merge and the rework, here is what changed and what is still open:

What changed since August

  • The lib/compat/wordpress-7.0 controllers this PR extended are gone from trunk, so the restore route now lives in a standalone Gutenberg_REST_Revision_Restore_Controller_7_3. The route is the same: POST /wp/v2/<base>/<id>/revisions/<id>/restore, for every post type with revisions, templates and template parts included.
  • The route returns the restored post as its own endpoint returns it for editing, so the editor shows it without another request.
  • restoreRevision() keeps what trunk added in Editor restoreRevisions: if there are unsaved changes, save these as a revision before restoring a revision #84590 (save an unpublished post first, Undo) and restores through the route. Undo restores the revision that held the post before the restore.
  • Without classic meta boxes the editor no longer reloads after a restore. With them it still does, as in the original PR, because the meta boxes are rendered by PHP. disableVisualRevisions and the classic screen fallback are removed.
  • New files are TypeScript.

Tested

  • PHPUnit: 14 tests for the route, covering the action firing once, revisioned meta with show_in_rest => false, the returned post, permissions, mismatched parents, disabled revisions and a template revision.
  • Unit tests for restoreRevision(), including Undo and the reload with meta boxes.
  • By hand on WordPress 7.1.5: the restore sends one POST .../restore and no post update, the action fires, hidden revisioned meta is restored, Undo works on consecutive restores, and a classic meta box shows its restored value after the reload.
  • The e2e tests were not run locally.

Still open

  • This needs a Trac ticket and a core PR before the backport changelog check can pass.
  • Undo is not offered when the editor reloads for meta boxes.
  • The route does not check the post lock, which revision.php does. The current client restore does not check it either.
  • Not tested with real-time collaboration. The restored fields are applied as an edit so collaborators should receive them, but that was not verified.

@github-actions

github-actions Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

📦 Bundle size

Size Change: +318 B (0%)

Total Size: 8.73 MB

📦 View Changed
Filename Size Change
build/scripts/edit-post/index.min.js 45 kB -233 B (-0.52%)
build/scripts/editor/index.min.js 576 kB +551 B (+0.1%)

e071dfa Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric 08582eb trunk % Change
timeToFirstByte 39.95 ms +9.14% -4.51% 44.05 ms +16.23% -6.02% -9.31%
largestContentfulPaint 68 ms +0% -5.88% 76 ms +5.26% -15.79% -10.53%
lcpMinusTtfb 27.65 ms +2.89% -16.09% 27.2 ms +18.38% -14.89% 1.65%
wpBeforeTemplate 20.55 ms +13.92% -2.38% 22.31 ms +24.97% -2.78% -7.89%
wpTemplate 15.17 ms +4.15% -5.74% 17.27 ms +9.9% -5.21% -12.16%
wpTotal 36.67 ms +9.16% -4.85% 40.33 ms +16.46% -5.7% -9.08%
wpMemoryUsage 7.76 MB +0% -0% 7.72 MB +0% -0% 0.46%
wpDbQueries 16 +0% -0% 16 +0% -0% 0%

front-end-classic-theme

Metric 08582eb trunk % Change
timeToFirstByte 33.45 ms +12.71% -2.39% 35.7 ms +8.54% -1.82% -6.3%
largestContentfulPaint 60 ms +13.33% -0% 64 ms +6.25% -0% -6.25%
lcpMinusTtfb 27.5 ms +4% -3.09% 28.9 ms +2.77% -2.08% -4.84%
wpBeforeTemplate 18.68 ms +10.49% -1.5% 19.68 ms +10.67% -2.08% -5.08%
wpTemplate 11.79 ms +3.31% -3.31% 12.74 ms +5.65% -3.69% -7.46%
wpTotal 30.67 ms +11.15% -2.61% 32.7 ms +9.14% -2.05% -6.21%
wpMemoryUsage 6.44 MB +0% -0% 6.41 MB +0% -0% 0.56%
wpDbQueries 13 +0% -0% 13 +0% -0% 0%

media-processing

Metric 08582eb trunk % Change
mediaProcessingJpeg 243.51 ms +4.21% -2.14% 249.52 ms +1.54% -0.97% -2.41%
mediaProcessingAvif 3935.71 ms +0.25% -0.33% 3993.39 ms +1.72% -0.75% -1.44%
mediaProcessingJpegToAvif 2719.79 ms +0.64% -0.52% 2791.28 ms +0.99% -0.55% -2.56%

media-upload

Metric 08582eb trunk % Change
jpegUploadProcessing 1480.67 ms +0.81% -0.84% 1476.88 ms +1.06% -1.33% 0.26%
pngUploadProcessing 254.96 ms +8.62% -1.17% 245.64 ms +4.92% -6.2% 3.79%
largeJpegUploadProcessing 1460.14 ms +0.62% -0.69% 1456.96 ms +1.28% -0.79% 0.22%
multipleImageUploadProcessing 1548.34 ms +0.71% -1.16% 1571.74 ms +0.16% -1.88% -1.49%

post-editor

Metric 08582eb trunk % Change
serverResponse 319.88 ms +5.31% -8.69% 323.37 ms +2.36% -6.98% -1.08%
firstPaint 333.57 ms +8.12% -3.69% 317.11 ms +6.4% -2.86% 5.19%
domContentLoaded 645.46 ms +3.29% -0.76% 636.86 ms +0.4% -0.9% 1.35%
loaded 646.28 ms +3.3% -0.76% 637.65 ms +0.4% -0.89% 1.35%
firstContentfulPaint 367.78 ms +3.02% -1.94% 355.61 ms +0.6% -0.63% 3.42%
firstBlock 1752.32 ms +9.05% -1.05% 1720.83 ms +0.79% -0.52% 1.83%
type 16.46 ms +3.1% -8.38% 16.58 ms +16.22% -9.47% -0.72%
typeWithoutInspector 16.19 ms +7.78% -10.5% 17.1 ms +2.46% -7.95% -5.32%
typeWithTopToolbar 22.05 ms +3.85% -1.32% 18.73 ms +16.5% -3.9% 17.73%
typeContainer 7.3 ms +5.48% -15.07% 6.87 ms +3.2% -11.06% 6.26%
focus 85.56 ms +5.75% -4.84% 85.09 ms +7.07% -5.24% 0.55%
firstFocus 214.76 ms +0% -0% 199.48 ms +0% -0% 7.66%
selectAll 294.35 ms +7.85% -0.59% 311.27 ms +3.17% -2.01% -5.44%
undo 23.65 ms +10.74% -1.86% 24.71 ms +6.11% -5.71% -4.29%
listViewOpen 31.65 ms +11.85% -3.03% 30.43 ms +2% -2.27% 4.01%
inserterOpen 32.76 ms +8.46% -6.78% 32.01 ms +3.06% -8.06% 2.34%
inserterHover 9.61 ms +6.35% -5.1% 9.73 ms +3.8% -2.06% -1.23%
inserterSearch 7.06 ms +5.1% -3.4% 7.28 ms +4.53% -8.38% -3.02%
loadPatterns 503.04 ms +1.37% -2.48% 506 ms +9.08% -1.03% -0.58%
wpTotal 311.27 ms +5.44% -9.03% 314.61 ms +2.1% -7.08% -1.06%
wpMemoryUsage 14.83 MB +0% -0% 14.77 MB +0% -0% 0.46%
wpDbQueries 55 +0% -0% 55 +0% -0% 0%

site-editor

Metric 08582eb trunk % Change
serverResponse 493.1 ms +3.27% -1.34% 487.92 ms +1.05% -7.59% 1.06%
firstPaint 473.04 ms +5.68% -7.39% 479.29 ms +3.63% -5.41% -1.3%
domContentLoaded 894.26 ms +3.38% -2.91% 867.12 ms +2.01% -0.78% 3.13%
loaded 895.49 ms +3.37% -2.92% 868.08 ms +2.04% -0.79% 3.16%
firstContentfulPaint 509.82 ms +3.49% -1.94% 488.69 ms +3.43% -1.94% 4.32%
firstBlock 2799.46 ms +3.2% -2.64% 2717.7 ms +1.81% -1.24% 3.01%
type 18.61 ms +7.95% -8.54% 18.98 ms +4.37% -14.65% -1.95%
navigate 120.03 ms +5.7% -3.01% 117.21 ms +14.81% -1.86% 2.41%
loadPatterns 1583.48 ms +1.07% -12.77% 1512.7 ms +5.49% -4.44% 4.68%
loadPages 991.57 ms +1.3% -3.72% 1004.89 ms +3.44% -1.9% -1.33%
wpTotal 483.49 ms +3.28% -1.35% 478 ms +1.1% -7.69% 1.15%
wpMemoryUsage 12.86 MB +0% -0% 12.80 MB +0% -0% 0.43%
wpDbQueries 45 +0% -0% 45 +0% -0% 0%

e071dfa Run

The classic revisions screen does not restore while another user holds
the edit lock, and the route should not either. With real-time
collaboration one of several editors holds the lock, so it is not
checked there.
@adamsilverstein adamsilverstein added the [Feature] History History, undo, redo, revisions, autosave. label Nov 28, 2026
The restore request comes from the editor of a user who is editing the post.
When another user takes over the lock, the editor already blocks the screen,
and saving a post through the REST API does not check the lock either.

This reverts commit 733a345.
The route is proposed for core in wordpress-develop#16315 (Trac #66865).

This branch has not been deployed

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

Labels

[Feature] History History, undo, redo, revisions, autosave. [Package] E2E Tests /packages/e2e-tests [Package] Edit Post /packages/edit-post [Package] Editor /packages/editor [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants