fix: guard WorktreeList getItemKey against stale virtualizer cache entries (#625)

When rows shrink (group collapse, worktree removal) while PR/issue data
arrives asynchronously, the virtualizer's elementsCache can hold stale
entries whose data-index exceeds the new rows length. measureElement
calls getItemKey for those stale indices, causing "Cannot read properties
of undefined (reading 'type')". Add a null guard matching the pattern
already used by FileExplorer and Search virtualizers.
This commit is contained in:
Jinjing 2026-04-13 23:31:50 -07:00 committed by GitHub
parent 49080b1d2d
commit 5bb03eb8f4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 0 deletions

View File

@ -323,6 +323,14 @@ const WorktreeList = React.memo(function WorktreeList() {
gap: 6,
getItemKey: (index) => {
const row = rows[index]
// Why: when rows shrink (group collapse, worktree removal) the
// virtualizer's elementsCache can still hold stale entries whose
// data-index exceeds the new rows length. measureElement calls
// getItemKey for those stale indices, so we need a fallback to
// avoid "Cannot read properties of undefined (reading 'type')".
if (!row) {
return `__stale_${index}`
}
return row.type === 'header' ? `hdr:${row.key}` : `wt:${row.worktree.id}`
}
})