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

Conversation

jeroen-huizer-conclusion

Pull request type

Bug fix (non-breaking change which fixes an issue)


Description

Both GoogleMap and LeafletMap components use the array index as key for the list-items.
This is discouraged: https://react.dev/learn/rendering-lists#rules-of-keys

In fact, this caused issues for us when rendering large amounts of locations and when filtering them.
This would present in hover-texts showing a different title than the popup. In fact, when examining the html, it turned out that multiple locations would get the same title.

I resolved the issue by using the object guid as key for the list. If there is no key (e.g. for static markers) i use a combination of the lat and lng.

What should be covered while testing?

  • Do locations render correctly, i.e. the mouse-over title corresponds with the text in the popup.
    • For large datasets
    • When filtering the locations that are rendered.

@jeroen-huizer-conclusion jeroen-huizer-conclusion requested a review from a team as a code owner July 11, 2025 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant