Commit 436e026
committed
[Real-time Collaboration] Fix sync issue on refresh (#76017)
* Add (passing) e2e reproduction for refresh and disconnect issue
* Reproduce the bug by actually typing in the document
* Include current doc state as UPDATE in initial queue alongside SYNC_STEP_1
Root Cause: createYjsDoc() in utils.ts calls stateMap.set(VERSION_KEY, CRDT_DOC_VERSION) which creates the first Yjs operation (clock=0) on the new Y.Doc. This happens before registerRoom() attaches the onDocUpdate handler. As a result, this operation is never captured as a regular UPDATE and never individually sent to peers.
After a page refresh, User A gets a new client ID. The stateMap.set creates clock=0 under this new ID, but it’s invisible to the sync system. When User A types, all operations start at clock=1+ and depend on clock=0. User B receives the typing updates but can’t integrate them because the missing dependency (clock=0) was never sent.
Why it’s flaky: Occasionally, the server triggers a COMPACTION (full state snapshot) that includes clock=0, resolving the issue within the test timeout. When no compaction arrives in time, the test fails.
Fix: In registerRoom(), include the current doc state as an UPDATE in the initial queue alongside the SYNC_STEP_1. This ensures any pre-existing operations (like the VERSION_KEY set) are sent to peers when the queue is resumed.
* Delay setting state instead of sending duplicative update
* Remove comment
---------
Co-authored-by: alecgeatches <[email protected]>
Co-authored-by: chriszarate <[email protected]>
Source: WordPress/gutenberg@dbddb421 parent 40d0856 commit 436e026
9 files changed
Lines changed: 172 additions & 169 deletions
File tree
- build
- modules
- scripts
- sync
- styles
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | | - | |
18 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
19 | 24 | | |
20 | 25 | | |
21 | 26 | | |
| |||
27 | 32 | | |
28 | 33 | | |
29 | 34 | | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | 35 | | |
41 | 36 | | |
42 | 37 | | |
| |||
47 | 42 | | |
48 | 43 | | |
49 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | 55 | | |
61 | 56 | | |
62 | 57 | | |
63 | 58 | | |
64 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| |||
0 commit comments