Repository navigation
Conversation
Fixes the regression introduced in WordPress#79947 where setCurrentRevisionId was used instead of openRevision, preventing the autosave revision entity from being fetched.
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
🤖 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. 🏷️ LabelsThis pull request needs exactly one label indicating its type, and has 0.
Read more about Type labels in Gutenberg. If you cannot add labels yourself, a reviewer can do it for you. |
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:
There were two issues present:
setCurrentRevisionIdinstead ofopenRevision, which only set state without explicitly dispatching the action to fetch the revision entity from the endpoint.getPreviousRevision()resolved tonullwhen no older revision existed in the revisions collection. This lead to a missing baseline for diff comparisons.As a result,
diffRevisionContent()anddiffRevisionHTML()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.
use-autosave-notice.js: Updated the notice action click handler to dispatchopenRevision( autosaveId )so the autosave entity is properly fetched and populated into the store.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 ingetPreviousRevision()viagetCurrentPost( state ). Normalizedtitle,content, andexcerptto{ raw: ... }to match the revision schema expected by the diff renderers.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
Sample TitleOne paragraph block with Hello world text.Unsaved new paragraph.Testing Instructions for Keyboard
N/A
Screenshots or screencast
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.