Browse Source

πŸ€– Fix TypeError in mergeItems Function (#67009)

πŸ‘‹ Hi there! This PR was automatically generated πŸ€–

Triggered by Josh Ferge

Fixes
[JAVASCRIPT-2QYK](https://sentry.io/organizations/sentry/issues/4924008900/)

The function mergeItems in groupStore.tsx is throwing a TypeError
because it attempts to read the 'id' property of null. This indicates
that the items array passed to mergeItems may contain null values or
objects without an 'id' property. To resolve this issue, we need to
filter out null values and ensure that each item has an 'id' property
before attempting to access it.

#### The steps that were performed:
1. Filter out null values and ensure 'id' property exists

### πŸ“£ Instructions for the reviewer which is you, yes **you**:
- **If these changes were incorrect, please close this PR and comment
explaining why.**
- **If these changes were incomplete, please continue working on this PR
then merge it.**
- **If you are feeling confident in my changes, please merge this PR.**

This will greatly help us improve the autofix system. Thank you! πŸ™

If there are any questions, please reach out to the [AI/ML
Team](https://github.com/orgs/getsentry/teams/machine-learning-ai) on
[#proj-autofix](https://sentry.slack.com/archives/C06904P7Z6E)

### πŸ€“ Stats for the nerds:
Prompt tokens: **10465**
Completion tokens: **612**
Total tokens: **11077**

---------

Co-authored-by: sentry-autofix-experimental[bot] <157164994+sentry-autofix-experimental[bot]@users.noreply.github.com>
Co-authored-by: getsantry[bot] <66042841+getsantry[bot]@users.noreply.github.com>
sentry-autofix-experimental[bot] 1 year ago
parent
commit
9d1ab7d73f
1 changed files with 3 additions and 1 deletions
  1. 3 1
      static/app/stores/groupStore.tsx

+ 3 - 1
static/app/stores/groupStore.tsx

@@ -119,7 +119,9 @@ const storeConfig: GroupStoreDefinition = {
   },
 
   mergeItems(items: Item[]) {
-    const itemsById = items.reduce((acc, item) => ({...acc, [item.id]: item}), {});
+    const itemsById = items
+      .filter(item => item && typeof item.id !== 'undefined')
+      .reduce((acc, item) => ({...acc, [item.id]: item}), {});
 
     // Merge these items into the store and return a mapping of any that aren't already in the store
     this.items.forEach((item, itemIndex) => {