Skip to content

Visual Revisions: Fix AutoSave view diff highlights unchanged blocks incorrectly - #83342

Open
Intenzi wants to merge 8 commits into
WordPress:trunkfrom
Intenzi:fix/visual-revisions-autosave-diff
Open

Intenzi wants to merge 8 commits into
WordPress:trunkfrom
Intenzi:fix/visual-revisions-autosave-diff

Conversation

@Intenzi

@Intenzi Intenzi commented Sep 22, 2026 •

Copy link
Copy Markdown

What?

Closes #80455

Fixes diff comparison when viewing an autosave revision so that unchanged content is not falsely highlighted in green as newly added.

Why?

When we observe a yellow notice: "There is an autosave of this post that is more recent than the version below."
Next to it is a button that says "View the autosave"

To render the revision diff screen that shows up upon clicking, the editor needs two pieces of data:

  • A: The Autosave's content (what was typed in the autosave).
  • B: The Previous content (what was saved in the post beforehand) so it can compare them.

There were two issues present:

  1. The notice handler was using setCurrentRevisionId instead of openRevision, which only set state without explicitly dispatching the action to fetch the revision entity from the endpoint.
  2. getPreviousRevision() resolved to null when no older revision existed in the revisions collection. This lead to a missing baseline for diff comparisons.

As a result, diffRevisionContent() and diffRevisionHTML() diffed the autosave against empty strings (""), causing the entire post (all original baseline paragraphs and the post title) to highlight in green as new additions.

How?

The issue comes from not having any previous revision in place to compare against, so in such a scenario we will compare it to the current state of the post. Thus ensuring the latest revision's changes are shown as new instead of the entire post.

  1. use-autosave-notice.js: Updated the notice action click handler to dispatch openRevision( autosaveId ) so the autosave entity is properly fetched and populated into the store.

  2. private-selectors.js: When the current revision is an autosave and has no older revision in the list, we will fall back to comparing against the current post content in getPreviousRevision() via getCurrentPost( state ). Normalized title, content, and excerpt to { raw: ... } to match the revision schema expected by the diff renderers.

  3. Added unit tests for the selector fallback and updated notice hook tests. Updated an e2e test which would check review diff against no prior revisions.

Testing Instructions

  1. Create a new draft post with some initial content:
    • Title: Sample Title
    • Content: One paragraph block with Hello world text.
  2. Do not publish nor click "Save draft".
  3. Add a second paragraph: Unsaved new paragraph.
  4. Trigger an autosave in the browser console:
    wp.data.dispatch( 'core/editor' ).autosave();
  5. Refresh the page, it will now show the "View the autosave" button after a few seconds of wait.
  6. Click on "View the autosave", observe that only 'Unsaved new paragraph' is highlighted in green.

Testing Instructions for Keyboard

N/A

Screenshots or screencast

Before After
For the default Hello World post
image
image
Followed via the testing instructions - new draft post
image
image

Use of AI Tools

AI assistance: Yes
Tool(s): Antigravity IDE
Model(s): Gemini 3.7 Flash (Low, Medium)
Used for: Help in identifying the error and locating the relevant code lines to fix, approach of fixing. Unit tests were written via AI. Final implementation was reviewed and tested by me.

@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: Intenzi <intenzi@git.wordpress.org>
Co-authored-by: himanshupathak95 <abcd95@git.wordpress.org>
Co-authored-by: habiburdev <habiburdev@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 github-actions Bot added the [Package] Editor /packages/editor label Sep 22, 2026
@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

👋 Welcome

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @Intenzi! In case you missed it, we'd love to have you join us in our Slack community.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

🏷️ Labels

This pull request needs exactly one label indicating its type, and has 0.

  • Required: any label starting with [Type].
  • Found: none.

Read more about Type labels in Gutenberg. If you cannot add labels yourself, a reviewer can do it for you.

@github-actions github-actions Bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Sep 22, 2026

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

First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Package] Editor /packages/editor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Visual Revisions: Autosave view incorrectly highlights unchanged base blocks and empty blocks as new additions

1 participant