Skip to content

fix: do not use array index as react list-key #1767

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,11 @@ function GoogleMap(props: GoogleMapsProps): ReactElement {
{locations
.concat(currentLocation ? [currentLocation] : [])
.filter(m => !!m)
.map((marker, index) => (
<GoogleMapsMarker key={`marker_${index}`} {...marker} />
.map(marker => (
<GoogleMapsMarker
key={`marker_${marker.id ?? marker.latitude + "_" + marker.longitude}`}
{...marker}
/>
))}
</GoogleMapComponent>
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export function LeafletMap(props: LeafletProps): ReactElement {
{locations
.concat(currentLocation ? [currentLocation] : [])
.filter(m => !!m)
.map((marker, index) => (
.map(marker => (
<MarkerComponent
icon={
marker.url
Expand All @@ -100,7 +100,7 @@ export function LeafletMap(props: LeafletProps): ReactElement {
: defaultMarkerIcon
}
interactive={!!marker.title || !!marker.onClick}
key={`marker_${index}`}
key={`marker_${marker.id ?? marker.latitude + "_" + marker.longitude}`}
eventHandlers={{
click: marker.title ? undefined : marker.onClick
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ exports[`Leaflet maps renders a map with current location 1`] = `
}
}
interactive={false}
key="marker_0"
key="marker_51.906688_4.48837"
position={
{
"lat": 51.906688,
Expand Down Expand Up @@ -251,7 +251,7 @@ exports[`Leaflet maps renders a map with markers 1`] = `
}
}
interactive={true}
key="marker_0"
key="marker_51.906688_4.48837"
position={
{
"lat": 51.906688,
Expand Down Expand Up @@ -288,7 +288,7 @@ exports[`Leaflet maps renders a map with markers 1`] = `
}
}
interactive={true}
key="marker_1"
key="marker_51.922823_4.479632"
position={
{
"lat": 51.922823,
Expand Down
3 changes: 2 additions & 1 deletion packages/pluggableWidgets/maps-web/src/utils/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ function fromDatasource(marker: DynamicMarkersType, item: ObjectItem): ModeledMa
longitude,
title: title ? title.get(item).value : "",
action: onClickAttribute ? onClickAttribute.get(item).execute : undefined,
customMarker: marker.customMarkerDynamic?.value?.uri
customMarker: marker.customMarkerDynamic?.value?.uri,
id: item.id
};
}

Expand Down
2 changes: 2 additions & 0 deletions packages/pluggableWidgets/maps-web/typings/shared.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface ModeledMarker {
title?: string;
customMarker?: string;
action?: () => void;
id?: string;
}

export interface Marker {
Expand All @@ -15,6 +16,7 @@ export interface Marker {
url: string;
onClick?: () => void;
title?: string;
id?: string;
}

export interface SharedProps extends Dimensions {
Expand Down
Loading