Real-time Collaboration: Use minimal save payload in persistCRDTDoc#77050
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. |
4108070 to
6ca408e
Compare
alecgeatches
left a comment
There was a problem hiding this comment.
Great change! Your explanation and reproduction is succinct, and your code changes look good. I've tested that this fixes the issue outlined in #77049. I believe it also fixes another behavior that causes the post to constantly re-save on each post open when a ping_status-like field is present, because the updated doc never hits the server. Great job, thanks!
|
I also want to note that not sending the post User saves go through |
|
Thank you! I had noticed some console errors in my browser while editing posts and went hunting for the root cause. Glad to see it is fixed! |
What?
Changes
persistCRDTDocto callsaveEntityRecordwith only the entity ID, instead of the entireeditedRecord.The existing post-type
__unstablePrePersisthook still creates and attachesmeta._crdt_documentduring the save. This keeps the CRDT persistence behavior while avoiding a full entity-record round trip through REST validation.Why?
persistCRDTDoccurrently sends the full entity record back through the REST API on page load. This causes 400 Bad Request errors when any field in the record doesn't pass strict REST schema validation — even though the post is otherwise valid.Two real-world examples:
ping_status: ""— WordPress core stores this when the Discussion settings pingback checkbox is unchecked. The REST schema only accepts"open"or"closed", so the round-trip fails.coauthorsthat returns objects, while a taxonomyrest_basewith the same name expects integers. When the full record is sent back, REST validation rejects the objects.Both are pre-existing data/schema issues that become visible because
persistCRDTDocunnecessarily round-trips the entire edited entity record. It only needs to trigger a save so the pre-persist hook can persist the CRDT document.How?
In
packages/core-data/src/resolvers.js,persistCRDTDocnow constructs a minimal save payload containing only the entity ID key. It keeps the current{ __unstableSkipSyncUpdate: true }option so the save response is not replayed into the sync document.The resolver test now covers the regression shape by including
ping_status: ""on the edited record and asserting that the save payload omits it.Testing Instructions
wp_collaboration_enabledto1).POST /wp-json/wp/v2/posts/{id}request can return 400 with"ping_status is not one of open and closed".Focused test run:
Result:
PASS— 36 tests passed.AI assistance
Closes #77049