Skip to content

Update FilteredActionList.tsx#7878

Merged
mattcosta7 merged 4 commits into
mainfrom
mattcosta7-patch-1
May 26, 2026
Merged

Update FilteredActionList.tsx#7878
mattcosta7 merged 4 commits into
mainfrom
mattcosta7-patch-1

Conversation

@mattcosta7
Copy link
Copy Markdown
Contributor

@mattcosta7 mattcosta7 commented May 25, 2026

Closes #

Fixes a crash in FilteredActionList where the virtualizer's getItemKey callback could be invoked with an index whose item was no longer present in items. @tanstack/react-virtual's measureElement can fire with a stale index after the list shrinks (e.g. while filtering), causing items[index] to be undefined and the subsequent item.key access to throw.

The callback now treats items[index] as possibly undefined and falls back to index.toString() as the key when the item has been removed.

Changelog

New

  • N/A

Changed

  • FilteredActionList: Guard against undefined entries in the virtualizer's getItemKey to prevent a runtime error when items are removed mid-render (e.g. during filtering).

Removed

  • N/A

Rollout strategy

  • Patch release
  • Minor release
  • Major release; if selected, include a written rollout or migration plan
  • None; if selected, include a brief description as to why

Testing & Reviewing

  • Open a story that renders FilteredActionList with virtualization enabled (e.g. the virtualized FilteredActionList story).
  • Type into the filter input quickly so that items shrinks while the virtualizer is still measuring previously rendered rows.
  • Before this change, this could throw Cannot read properties of undefined (reading 'key') from getItemKey. After this change, no error is thrown and the list re-renders with the filtered items.

Merge checklist

@mattcosta7 mattcosta7 self-assigned this May 25, 2026
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 25, 2026

🦋 Changeset detected

Latest commit: 178214d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/react Patch

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

@github-actions github-actions Bot added the integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm label May 25, 2026
@github-actions
Copy link
Copy Markdown
Contributor

⚠️ Action required

👋 Hi, this pull request contains changes to the source code that github/github-ui depends on. If you are GitHub staff, test these changes with github/github-ui using the integration workflow. Check the integration testing docs for step-by-step instructions. Or, apply the integration-tests: skipped manually label to skip these checks.

To publish a canary release for integration testing, apply the Canary Release label to this PR.

Add guard clause for undefined items in getItemKey.
@github-actions github-actions Bot requested a deployment to storybook-preview-7878 May 25, 2026 23:50 Abandoned
@github-actions github-actions Bot temporarily deployed to storybook-preview-7878 May 26, 2026 00:02 Inactive
@mattcosta7 mattcosta7 marked this pull request as ready for review May 26, 2026 12:56
@mattcosta7 mattcosta7 requested a review from a team as a code owner May 26, 2026 12:56
@mattcosta7 mattcosta7 requested review from Copilot and liuliu-dev and removed request for Copilot May 26, 2026 12:56
@mattcosta7 mattcosta7 enabled auto-merge May 26, 2026 17:36
@mattcosta7 mattcosta7 added the integration-tests: skipped manually Changes in this PR do not require an integration test label May 26, 2026
Copilot AI review requested due to automatic review settings May 26, 2026 17:46
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 getItemKey to avoid reading .key from an undefined item and fall back to index.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

Comment on lines +303 to 305
const item = items[index] as ItemInput | undefined
if (!item) return index.toString()
return item.key ?? item.id?.toString() ?? index.toString()
@mattcosta7 mattcosta7 added this pull request to the merge queue May 26, 2026
Merged via the queue into main with commit 8c468fd May 26, 2026
54 checks passed
@mattcosta7 mattcosta7 deleted the mattcosta7-patch-1 branch May 26, 2026 18:01
@primer primer Bot mentioned this pull request May 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm integration-tests: skipped manually Changes in this PR do not require an integration test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants