Repository navigation
Commit 1647fb3
fix(grid): an earlier save's Undo right after a newer save keeps the newer row on screen (#36064)
<!-- claude-projects-attribution: {"github_login":"os-sales"} -->
_Requested by **Sales** · [project
thread](https://claude.ai/code/project/chan_01D5bWFY3rFzgJcytD5gD4Uu?thread=cmsg_01D5bWFY3rFzgJcytD5gD4UuVwX4pUdM1qvNLSqRZNSvv3)_
Fixes #35999
Clause-②: no
Metadata-protocol: none
Skills-docs: none
repo:objectstack#1 · os-sales · session_01L6bhgW85kwjGaz7HqsmEuv
## 维护者速读
- 用户能看到什么变化:列表里先后改了同一行的两个单元格,随即撤销较早那一次时,这一行不再退回最初读到的旧值,较新那次修改留在屏幕上。
- 为什么做:这是列表单元格自动保存与撤销那一组工作里的一处时序缺陷,它也让界面测试在无关的 PR 上偶尔变红。
- 出错会怎样:只有显示错,服务器上的数据一直是对的,下次刷新列表就恢复;改动可以直接撤回。
- 要你做什么:无。
## What changes
A select-first grid draws an Undo's answer over the row as the grid
shows it now. `currentRowOf` reads that row from `rowPatchesRef`. The
ref was mirrored from the `rowPatches` state by a passive `useEffect`,
and the save's `setRowPatches` runs after an `await`, so it is a
default-lane update. Its effects are therefore scheduled after the
commit instead of inside it. That leaves a window in which the newer
save is already in the DOM while the ref still holds the earlier save's
patch. An Undo of the earlier save inside that window:
1. read the stale patch row (old name, the earlier save's amount);
2. failed the `held.row === row` check in `writeRowInPlace` against the
real state, so it re-based the new patch onto that stale row;
3. `patchedRowOf` rejected a patch whose `base` is not the loaded row,
so the grid drew the row as first read (`alpha` / `10`) until the next
load.
The server's record was right throughout. The guard came from
`writtenVersionsRef`, which was always written synchronously. That is
why the CI failure was the `getByText('A2')` after `findByText('10')`,
and never the `If-Match` assertion before it.
Fix: `writeRowInPlace`, the only writer of the patches, builds the next
map from the ref, assigns the ref, then calls `setRowPatches(next)`. The
mirroring effect is gone. Nothing else sets the patches; a load does not
reset them, because a load hands the grid new row objects and each patch
stops applying by its `base`. So no effect is needed for load-driven
resets.
Files to read first, by risk:
1. `ui/packages/plugin-grid/src/ObjectGrid.tsx`: the `writeRowInPlace`
hunk (ref set together with the state) and the removed `useEffect`
beside `rowPatchesRef`.
2.
`ui/packages/plugin-grid/src/__tests__/ObjectGrid.autosave-35685.test.tsx`:
the new test "an earlier save's Undo pressed the moment a newer save is
drawn keeps the newer save on screen". The existing "an earlier save's
Undo is guarded by the newest version of its record" is unchanged.
Two-minute check: `pnpm --dir ui exec vitest run
packages/plugin-grid/src/__tests__/ObjectGrid.autosave-35685.test.tsx`
should report 19 passed.
## Tests
The new test presses the earlier save's toast Undo inside a
`MutationObserver` callback the moment `A2` reaches the DOM. That is a
microtask after React's commit and before the render's scheduled passive
effects, so the test lands in the window on every run, not only under
load. It asserts the third update's arguments and `If-Match`, that `A2`
is still shown, and that `alpha` is not.
<details><summary>Fixed tree (1ed9d92): window test 3/3, whole file
19/19, load loop 108/108</summary>
```
== leg fixed HEAD 1ed9d92 markers: ref-assign=1 effect=0
window test run 1 exit=0 Tests 1 passed | 18 skipped (19)
window test run 2 exit=0 Tests 1 passed | 18 skipped (19)
window test run 3 exit=0 Tests 1 passed | 18 skipped (19)
whole file exit=0 Tests 19 passed (19)
RESULT tag=fixed-load runs=108 fail=0
```
The load loop ran 3 parallel loops of the original "is guarded by the
newest version" test, with 1 `yes` CPU burner, on a shared 4-core box.
</details>
<details><summary>Ablation (fix reverted to main's code): window test
red 3/3, with the CI failure's signature; restore proven</summary>
The ablation reverted both halves through
`scripts/ablation-replace.mjs`: the mirroring `useEffect` was put back,
and the functional `setRowPatches` updater was put back in place of the
ref assignment. Each mutation showed the anchor moving 1 -> 0 and the
blob changing.
```
== leg ablated HEAD 1ed9d92 markers: ref-assign=0 effect=1
window test run 1 exit=1 Tests 1 failed | 18 skipped (19)
window test run 2 exit=1 Tests 1 failed | 18 skipped (19)
window test run 3 exit=1 Tests 1 failed | 18 skipped (19)
whole file exit=1 Tests 1 failed | 18 passed (19)
TestingLibraryElementError: Unable to find an element with the text: A2.
RESULT tag=ablated-load runs=33 fail=0
ablation-replace: ok restored: blob == HEAD (f49d4e1) and `git diff HEAD` is empty
```
On the ablated (main-equivalent) tree, the original test passed 33/33
under this box's load. The CI flake did not reproduce here by load
alone, which matches the 3/3 and 5x18 local greens on the card. The
deterministic window test is what pins the defect.
</details>
## Acceptance notes
- The original flaky test is unchanged. It now has nothing to race: the
ref is current from the moment the newer save's state is set.
- No skip, quarantine, retry or timeout change.
## Verification
<details><summary>Derived gates (dispatch-gates --commands,
1ed9d92)</summary>
```
dispatch-gates --ran: 39 derived famil(ies) accounted for, 39 run, 0 NOT-MEASURED; all 39 exit 0
(incl. pnpm --dir ui exec vitest run scripts/: Test Files 172 passed | 2 skipped, Tests 5111 passed | 2 skipped)
pnpm --filter @object-ui/plugin-grid run type-check (after building its ^... closure): exit 0
scoped cell-selection save tests (autosave-35685, cellSelection-35684, requiredPrompt-35956,
inCellSelectMultipleRouting-35688, objectGridRowPatch-35685): Test Files 5 passed, Tests 42 passed
pnpm --dir ui run check:new-line-citations: 0 new citation(s), exit 0
overlap-check --branch=HEAD: clean vs origin/main, #36054, #36045, #36024 (all share ObjectGrid.tsx, all merge cleanly)
```
The whole @object-ui/plugin-grid suite and the Test UI shards are left
to CI.
</details>
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01L6bhgW85kwjGaz7HqsmEuv
Co-authored-by: Claude <noreply@anthropic.com>1 parent 33d0169 commit 1647fb3
3 files changed
Lines changed: 51 additions & 8 deletions
File tree
- .changeset
- ui/packages/plugin-grid/src
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
907 | 907 | | |
908 | 908 | | |
909 | 909 | | |
910 | | - | |
| 910 | + | |
| 911 | + | |
911 | 912 | | |
912 | 913 | | |
913 | | - | |
914 | 914 | | |
915 | 915 | | |
916 | 916 | | |
| |||
2879 | 2879 | | |
2880 | 2880 | | |
2881 | 2881 | | |
2882 | | - | |
2883 | | - | |
2884 | | - | |
2885 | | - | |
2886 | | - | |
2887 | | - | |
| 2882 | + | |
| 2883 | + | |
| 2884 | + | |
| 2885 | + | |
| 2886 | + | |
| 2887 | + | |
| 2888 | + | |
| 2889 | + | |
| 2890 | + | |
2888 | 2891 | | |
2889 | 2892 | | |
2890 | 2893 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
334 | 334 | | |
335 | 335 | | |
336 | 336 | | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
337 | 367 | | |
338 | 368 | | |
339 | 369 | | |
| |||
0 commit comments