Commit 186b3bd
committed
fix(virtual-core): don't call getItemKey with a stale index in RO disconnect cleanup
Commit 843690b added an elementsCache cleanup in the ResizeObserver
disconnect path that looked up the cache key via getItemKey(index).
When items have been removed from the end of the list, that index can
be past items.length, so any user-supplied getItemKey that indexes into
the data array throws — exactly the bug PR #1148 had fixed for the
non-cleanup paths.
Fix: find the cache entry by node identity instead. Iterating
elementsCache is O(visible-window), which is fine for a path that only
fires on disconnect, and it naturally handles the React-replaced-the-
node-under-the-same-key case (the === check just won't match).
The stale-index e2e test now passes on both react-virtual and
angular-virtual, and the two RO-cleanup unit tests still pass since
they were written against node identity, not key lookup.1 parent ab9c00f commit 186b3bd
2 files changed
Lines changed: 21 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
429 | 429 | | |
430 | 430 | | |
431 | 431 | | |
432 | | - | |
433 | | - | |
434 | | - | |
435 | | - | |
436 | | - | |
437 | | - | |
438 | | - | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
439 | 444 | | |
440 | 445 | | |
441 | 446 | | |
| |||
0 commit comments