Commit fb17f8e
[OPIK-8005] [FE] fix: scope hydration cancellation to the effect run (Baz review)
Baz caught a real bug in the previous commit, and it is worth being precise that
the new early-return path made a latent flaw dangerous rather than merely
inelegant.
cancelledRef is a single ref shared across every effect run, and the effect body
reset it to false on entry. React runs the previous run's cleanup before the next
body, so the sequence was: run 1 starts hydrating dataset A and installs cleanup
-> dataset changes -> cleanup sets cancelled = true -> run 2 enters and resets it
to false, un-cancelling run 1's still-pending loop -> run 1's continuation passes
its post-await check and calls setHydratedItems on the new array.
Before this PR the only early return sat after setHydratedItems([]), so that
stale continuation's prev.map() ran over an empty array and produced nothing —
harmless. The no-media early return added in the previous commit sits after
setHydratedItems(datasetItems) with a populated array, so the same continuation
writes dataset A's data into dataset B's array at a positional index. That is
silent cross-dataset corruption, reachable by switching dataset or page size
while a media-bearing dataset is still hydrating.
Replace the shared ref with a `cancelled` flag scoped to each effect run. Each
run observes only its own flag, so early-returning without installing cleanup
cannot resurrect an older run's loop. This also fixes the pre-existing empty-
dataset path and the setState-after-unmount case, and removes the useRef import.
Verified: tsc, eslint --max-warnings=0, prettier, and the full vitest suite
(150 files, 2229 tests) all pass.
Refs: OPIK-8005, CUST_6878, AI_546
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent e1832ee commit fb17f8e
1 file changed
Lines changed: 12 additions & 6 deletions
Lines changed: 12 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | 13 | | |
15 | 14 | | |
16 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
17 | 23 | | |
18 | 24 | | |
19 | 25 | | |
| |||
48 | 54 | | |
49 | 55 | | |
50 | 56 | | |
51 | | - | |
| 57 | + | |
52 | 58 | | |
53 | 59 | | |
54 | 60 | | |
55 | | - | |
| 61 | + | |
56 | 62 | | |
57 | 63 | | |
58 | 64 | | |
| |||
67 | 73 | | |
68 | 74 | | |
69 | 75 | | |
70 | | - | |
| 76 | + | |
71 | 77 | | |
72 | 78 | | |
73 | 79 | | |
| |||
0 commit comments