RTC: Fix stale CRDT document persisted on save#75975
Merged
chriszarate merged 4 commits intotrunkfrom Mar 2, 2026
Merged
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Fix stale CRDT document being persisted during save when real-time collaboration is enabled.
Why?
When sync is enabled, Y.Doc updates are deferred via
setTimeout(0)for performance.saveEntityRecordcalls__unstablePrePersistto serialize the CRDT document, but it was doing so without yielding to the event loop first. This meant the serialized_crdt_documentwas stale — it didn't include the most recent Y.Doc updates. On reload,_applyPersistedCrdtDocdetected the mismatch and triggered an unnecessary reconciliation save.How?
setTimeout(0)yield insidesaveEntityRecordbefore calling__unstablePrePersist, only whensyncConfigis present. This flushes any pending deferred Y.Doc updates before serialization.waitForFunction/evaluateblocks from the collaboration persistence E2E tests into three reusableCollaborationUtilshelpers:waitForEntityReady,waitForEntityReadyAndSaveSettled, andgetCrdtDocument.persisted CRDT document matches content after save and reload) that verifies the CRDT document is identical before and after a save-reload cycle.Testing Instructions
posts/:idto see REST API calls towp/v2/posts/:id.On
trunk(before this PR):POSTrequest toposts/:id.POSTrequest toposts/:idfires automatically after reload — this is the unnecessary reconciliation save caused by the stale CRDT document.On this branch (after this PR):
POSTrequest toposts/:id.POSTrequest toposts/:idfires — the persisted CRDT document is up-to-date so no reconciliation save is triggered.Automated
npx playwright test --config test/e2e/playwright.config.ts test/e2e/specs/editor/collaboration/collaboration-persistence.spec.tsAll 3 tests should pass. The third test (
persisted CRDT document matches content after save and reload) fails without theactions.jsfix.Testing Instructions for Keyboard
N/A — no UI changes.