Core Data: Replace mutated edits with original record to fix dirty state#77611
Core Data: Replace mutated edits with original record to fix dirty state#77611karthikeya-io wants to merge 1 commit intoWordPress:trunkfrom
Conversation
|
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. |
|
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.
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. |
|
I think similar issue was fixed recently. See #77529. cc @alecgeatches |
| undefined, | ||
| true, | ||
| edits | ||
| record |
There was a problem hiding this comment.
Changing to record means that entityConfig.__unstablePrePersist never runs for this save, while it might fix the mentioned issue, it will break something else.
There was a problem hiding this comment.
Thanks for checking this. I replaced edits with record in the 6th argument of receiveEntityRecords (which happens after the save). This argument seems to be used as persistedEdits to reset the user's edits from the store. So I think this shouldn't affect __unstablePrePersist or the data we save to the database.
What?
Closes #77610
This PR fixes the issue where the editor gets stuck in a dirty state ("Changes you made may not be saved" warning) after successfully restoring a visual revision or saving a post that contains meta updates (like when using the Footnotes block).
Why?
When
saveEntityRecordprepares to send meta edits to the server,__unstablePrePersist()changes theedits.metapayload by injecting an internal collaborative editing key (_crdt_document).After the save succeeds,
saveEntityRecorddispatchesreceiveEntityRecordsto clear the saved edits from the store. Previously, it passed the mutatededitsvariable as thepersistedEditsargument.Because the Redux reducer compares the original edits in the store (which lack
_crdt_document) against this mutatedpersistedEditsobject usingfastDeepEqual, the comparison fails. The reducer incorrectly assumes the save was incomplete and leaves the post permanently "dirty".How?
This PR updates
saveEntityRecordto pass the original, un-mutatedrecordtoreceiveEntityRecordsaspersistedEdits. This ensures the equality check succeeds and the editor correctly clears its dirty state.Testing Instructions
Visual Revisions
Test 2: Meta-updating Blocks
Screenshots or screencast
Before
After
dirty_editor_state.mov
Use of AI Tools