Update FilteredActionList.tsx#7878
Conversation
🦋 Changeset detectedLatest commit: 178214d The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Add guard clause for undefined items in getItemKey.
There was a problem hiding this comment.
Pull request overview
Fixes a runtime crash in FilteredActionList virtualization when @tanstack/react-virtual calls getItemKey with a stale index after the items array shrinks (e.g. during filtering), by handling items[index] being undefined.
Changes:
- Add a defensive guard in the virtualizer’s
getItemKeyto avoid reading.keyfrom anundefineditem and fall back toindex.toString(). - Add a patch changeset documenting the crash fix.
Show a summary per file
| File | Description |
|---|---|
| packages/react/src/FilteredActionList/FilteredActionList.tsx | Prevents a virtualization-related crash by guarding against stale indices in getItemKey. |
| .changeset/filtered-action-list-undefined-item-key.md | Adds a patch changeset describing the FilteredActionList crash fix. |
Copilot's findings
- Files reviewed: 2/2 changed files
- Comments generated: 1
| const item = items[index] as ItemInput | undefined | ||
| if (!item) return index.toString() | ||
| return item.key ?? item.id?.toString() ?? index.toString() |
Closes #
Fixes a crash in
FilteredActionListwhere the virtualizer'sgetItemKeycallback could be invoked with an index whose item was no longer present initems.@tanstack/react-virtual'smeasureElementcan fire with a stale index after the list shrinks (e.g. while filtering), causingitems[index]to beundefinedand the subsequentitem.keyaccess to throw.The callback now treats
items[index]as possiblyundefinedand falls back toindex.toString()as the key when the item has been removed.Changelog
New
Changed
FilteredActionList: Guard againstundefinedentries in the virtualizer'sgetItemKeyto prevent a runtime error when items are removed mid-render (e.g. during filtering).Removed
Rollout strategy
Testing & Reviewing
FilteredActionListwith virtualization enabled (e.g. the virtualized FilteredActionList story).itemsshrinks while the virtualizer is still measuring previously rendered rows.Cannot read properties of undefined (reading 'key')fromgetItemKey. After this change, no error is thrown and the list re-renders with the filtered items.Merge checklist