fix: avoid stale worktree card remeasurement (#626)
* fix: guard WorktreeList getItemKey against stale virtualizer cache entries 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. * fix: avoid stale worktree card remeasurement
This commit is contained in:
@@ -394,9 +394,17 @@ const WorktreeList = React.memo(function WorktreeList() {
|
||||
|
||||
useLayoutEffect(() => {
|
||||
virtualizer.elementsCache.forEach((element) => {
|
||||
// Why: elementsCache can hold stale DOM nodes whose data-index
|
||||
// exceeds the current rows length (e.g. after a group collapse).
|
||||
// Measuring a stale element feeds a detached node's size into the
|
||||
// virtualizer, corrupting layout and causing overlapping cards.
|
||||
const idx = parseInt(element.getAttribute('data-index') ?? '', 10)
|
||||
if (Number.isNaN(idx) || idx >= rows.length) {
|
||||
return
|
||||
}
|
||||
virtualizer.measureElement(element)
|
||||
})
|
||||
}, [prCacheLen, issueCacheLen, virtualizer])
|
||||
}, [prCacheLen, issueCacheLen, virtualizer, rows.length])
|
||||
|
||||
const navigateWorktree = useCallback(
|
||||
(direction: 'up' | 'down') => {
|
||||
|
||||
Reference in New Issue
Block a user