Commit dc98f0f
authored
fix(ui): stale data modal shown when onChange starts while save is in-flight (#15960)
# Overview
Fixes a race condition where the "Document Modified" modal incorrectly
appears
after a user types and saves their own document.
## Key Changes
- Added `saveCounterRef` (incremented in `onSubmit`) and `isSavingRef`
(set in `onSubmit`, cleared in `onSave`) to the Edit view
- Both are captured at the start of each `onChange` and used to suppress
the stale data modal when the newer `updatedAt` the server sees came
from our own save
- Added CPU throttling to an existing lexical e2e test to reliably
reproduce the race in CI environments
<img width="1790" height="1198" alt="Screenshot 2026-03-16 at 9 32
31 AM"
src="https://github.com/user-attachments/assets/d95fffb0-fa5f-44aa-98ac-41a8564daff3"
/>
## Design Decisions
`saveCounterRef` handles form-state requests that start before
`onSubmit` — the counter
advances mid-flight, so `saveCounterAtStart` diverges and the modal is
suppressed.
`isSavingRef` handles the complementary case where a queued `onChange`
starts after
`onSubmit` (so the counter already matches) but before `onSave` has
updated
`originalUpdatedAtRef` with the new timestamp. Capturing it before the
async call means
the guard fires correctly even if the save completes before the response
arrives.
The two-user scenario is unaffected — both refs are per-instance, so
another user's
save doesn't influence the local state and the modal still appears
correctly.1 parent da212fd commit dc98f0f
File tree
4 files changed
+108
-68
lines changed- packages/ui/src/views/Edit
- test
- lexical
- collections/Lexical/e2e/main
- locked-documents
4 files changed
+108
-68
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
186 | 186 | | |
187 | 187 | | |
188 | 188 | | |
| 189 | + | |
189 | 190 | | |
190 | 191 | | |
191 | 192 | | |
| |||
316 | 317 | | |
317 | 318 | | |
318 | 319 | | |
| 320 | + | |
319 | 321 | | |
320 | 322 | | |
321 | 323 | | |
| |||
467 | 469 | | |
468 | 470 | | |
469 | 471 | | |
470 | | - | |
| 472 | + | |
471 | 473 | | |
472 | 474 | | |
| 475 | + | |
473 | 476 | | |
474 | 477 | | |
475 | 478 | | |
| |||
531 | 534 | | |
532 | 535 | | |
533 | 536 | | |
534 | | - | |
535 | | - | |
536 | | - | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
537 | 544 | | |
538 | 545 | | |
539 | 546 | | |
| |||
627 | 634 | | |
628 | 635 | | |
629 | 636 | | |
| 637 | + | |
630 | 638 | | |
631 | 639 | | |
632 | 640 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
166 | 166 | | |
167 | 167 | | |
168 | 168 | | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
169 | 209 | | |
170 | 210 | | |
171 | 211 | | |
| |||
456 | 496 | | |
457 | 497 | | |
458 | 498 | | |
459 | | - | |
460 | | - | |
| 499 | + | |
| 500 | + | |
461 | 501 | | |
462 | 502 | | |
463 | 503 | | |
| |||
466 | 506 | | |
467 | 507 | | |
468 | 508 | | |
469 | | - | |
470 | | - | |
| 509 | + | |
| 510 | + | |
471 | 511 | | |
472 | 512 | | |
473 | 513 | | |
| |||
1566 | 1606 | | |
1567 | 1607 | | |
1568 | 1608 | | |
1569 | | - | |
1570 | 1609 | | |
1571 | 1610 | | |
1572 | 1611 | | |
| |||
1576 | 1615 | | |
1577 | 1616 | | |
1578 | 1617 | | |
1579 | | - | |
1580 | 1618 | | |
1581 | 1619 | | |
1582 | | - | |
1583 | 1620 | | |
1584 | 1621 | | |
1585 | 1622 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
199 | 199 | | |
200 | 200 | | |
201 | 201 | | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
| 202 | + | |
210 | 203 | | |
211 | 204 | | |
212 | 205 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1757 | 1757 | | |
1758 | 1758 | | |
1759 | 1759 | | |
1760 | | - | |
1761 | | - | |
1762 | | - | |
1763 | | - | |
1764 | | - | |
1765 | | - | |
1766 | | - | |
1767 | | - | |
1768 | | - | |
1769 | | - | |
1770 | | - | |
1771 | | - | |
1772 | | - | |
| 1760 | + | |
| 1761 | + | |
| 1762 | + | |
1773 | 1763 | | |
1774 | | - | |
1775 | | - | |
1776 | | - | |
1777 | | - | |
1778 | | - | |
1779 | | - | |
1780 | | - | |
| 1764 | + | |
| 1765 | + | |
| 1766 | + | |
| 1767 | + | |
| 1768 | + | |
| 1769 | + | |
1781 | 1770 | | |
1782 | | - | |
1783 | | - | |
1784 | | - | |
| 1771 | + | |
| 1772 | + | |
| 1773 | + | |
1785 | 1774 | | |
1786 | | - | |
1787 | | - | |
1788 | | - | |
1789 | | - | |
1790 | | - | |
| 1775 | + | |
| 1776 | + | |
| 1777 | + | |
| 1778 | + | |
| 1779 | + | |
| 1780 | + | |
| 1781 | + | |
| 1782 | + | |
| 1783 | + | |
| 1784 | + | |
| 1785 | + | |
| 1786 | + | |
| 1787 | + | |
| 1788 | + | |
| 1789 | + | |
| 1790 | + | |
| 1791 | + | |
1791 | 1792 | | |
1792 | 1793 | | |
1793 | 1794 | | |
| |||
2180 | 2181 | | |
2181 | 2182 | | |
2182 | 2183 | | |
2183 | | - | |
2184 | | - | |
| 2184 | + | |
| 2185 | + | |
| 2186 | + | |
2185 | 2187 | | |
2186 | | - | |
2187 | | - | |
2188 | | - | |
2189 | | - | |
2190 | | - | |
2191 | | - | |
2192 | | - | |
2193 | | - | |
2194 | | - | |
2195 | | - | |
| 2188 | + | |
| 2189 | + | |
| 2190 | + | |
| 2191 | + | |
| 2192 | + | |
| 2193 | + | |
2196 | 2194 | | |
2197 | | - | |
2198 | | - | |
2199 | | - | |
2200 | | - | |
| 2195 | + | |
| 2196 | + | |
| 2197 | + | |
2201 | 2198 | | |
2202 | | - | |
2203 | | - | |
| 2199 | + | |
| 2200 | + | |
| 2201 | + | |
| 2202 | + | |
2204 | 2203 | | |
2205 | | - | |
2206 | | - | |
2207 | | - | |
| 2204 | + | |
| 2205 | + | |
| 2206 | + | |
| 2207 | + | |
| 2208 | + | |
| 2209 | + | |
2208 | 2210 | | |
2209 | 2211 | | |
2210 | 2212 | | |
| |||
0 commit comments