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 2 commits into
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. |
|
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.
There was a problem hiding this comment.
It affects the existing "contract" established before our use of meta._crdt_document. The values modified by __unstablePrePersist were previously counted as persisted edits; now, they will not be. The original behavior seems correct, because that's the actual value saved to the DB.
cc @chriszarate, @jsnajdr
There was a problem hiding this comment.
The __unstablePrePersist callback was originally used to "clean up" the data before sending them to server and saving. Add a missing title, set the correct status, handle auto-drafts. It was introduced in commit 85173ee, it's instructive to read it, not hard to understand.
Today this callback is also used to add the meta._crdt_document field. This doesn't look like a good place to do it. It's not a cleanup, but a regular course of business when RTC is enabled.
These two functions, cleanup and RTC, should be completely separated. The RTC part can happen directly in saveEntityRecord. This function already calls getSyncManager().update, now it could also call getSyncManager().createPersistedCRDTDoc when appropriate.
There was a problem hiding this comment.
Thanks for the feedback! I have moved the code that adds _crdt_document to the meta payload directly into saveEntityRecord and passed the edits variable, which includes values modified by __unstablePrePersist, to receiveEntityRecords to reset the edits. Excluding _crdt_document from this variable fixes the dirty state issue, as it is now added directly to the fetch payload.
7e1f385 to
b8a3302
Compare
b8a3302 to
88b40f3
Compare
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