Repository navigation
fix(geo): fix React unique-key warning in Choropleth legends - #2845
Open
aloktomarr wants to merge 2 commits into
Open
aloktomarr wants to merge 2 commits into
aloktomarr wants to merge 2 commits into
Conversation
The legends layer returned a bare legends.map array, unlike the features and graticule layers which return keyed elements. Under React 19 this triggers a missing-key warning. Wrap the legends layer in a keyed Fragment so it matches the other layers. Closes plouc#2801.
Contributor
Author
|
The warning comes from the legends layer in Choropleth: it returns a bare legends.map(...) array, while the features and graticule layers return keyed elements. I've opened a PR that wraps the legends layer in a keyed like the others, which removes the warning. Added a test too. |
plouc
approved these changes
Jul 21, 2026
Owner
|
@aloktomarr, tests are failing. |
Contributor
Author
|
Sorry my test had issues. Fix (just the test, the Choropleth.js change is unchanged): |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2801
Problem
<ResponsiveChoropleth>/<Choropleth>with alegendsprop logs a React "Each child in a list should have a unique key prop" warning (reported under React 19). The stack trace points at the nestedArray.mapcalls inChoropleth.Root cause
In
Choropleth,layers.map(...)renders each layer. Thefeaturesandgraticulelayers return keyed elements (<Fragment key="features">,<GeoGraticule key="graticule">), but thelegendslayer returned a barelegends.map(...)array with no keyed wrapper — so it's the odd one out.Fix
Wrap the
legendslayer in a keyed<Fragment key="legends">, exactly like thefeatureslayer. Rendered output is unchanged; the key warning is resolved.Testing
Added
packages/geo/tests/Choropleth.test.js, which renders a Choropleth with a legend and asserts the legend renders and no React key warning is logged.