Skip to content

Update getUniqueKey to use fallback for undefined IDs - #22

Open
Avi-ADAM wants to merge 1 commit into
mediakular:masterfrom
Avi-ADAM:patch-1
Open

Update getUniqueKey to use fallback for undefined IDs#22
Avi-ADAM wants to merge 1 commit into
mediakular:masterfrom
Avi-ADAM:patch-1

Conversation

@Avi-ADAM

Copy link
Copy Markdown
Contributor

function getUniqueKey(row) {
return uniqueRowIds.find(x => x.row.id === row.id)?.id;
}

uniqueRowIds and the rendered gridData are populated by two separate $effects that both react to the filtered data changing. Clicking a filter button changes filteredActs, which can update gridData (via the grid derived) and uniqueRowIds in different reactive ticks. In that transient mismatch, some rows in gridData have no matching entry in the (temporarily stale) uniqueRowIds, so getUniqueKey returns undefined for more than one row → Svelte's each_key_duplicate error.

Fix

the key always falls back to the row's own id (which is always defined and unique in your data) instead of failing when the lookup race happens:

  • return uniqueRowIds.find(x => x.row.id === row.id)?.id;
  • return uniqueRowIds.find(x => x.row.id === row.id)?.id ?? row?.id ?? row;

function getUniqueKey(row) {
  return uniqueRowIds.find(x => x.row.id === row.id)?.id;
}

uniqueRowIds and the rendered gridData are populated by two separate $effects that both react to the filtered data changing. Clicking a filter button changes filteredActs, which can update gridData (via the grid derived) and uniqueRowIds in different reactive ticks. In that transient mismatch, some rows in gridData have no matching entry in the (temporarily stale) uniqueRowIds, so getUniqueKey returns undefined for more than one row → Svelte's each_key_duplicate error.

Fix

 the key always falls back to the row's own id (which is always defined and unique in your data) instead of failing when the lookup race happens:

- return uniqueRowIds.find(x => x.row.id === row.id)?.id;
+ return uniqueRowIds.find(x => x.row.id === row.id)?.id ?? row?.id ?? row;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant