You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: Key text children of SpaceBetween, Grid, and ColumnLayout by position - #5340
SpaceBetween, Grid, and flexible ColumnLayout wrap each flattened child in a <div> keyed by the child's key. flattenChildren passes strings and numbers through without a key, so their wrappers got key={undefined}. Any of these components with a text child next to an element, such as <SpaceBetween><Box>...</Box>{t('...')}</SpaceBetween>, logged "Each child in a list should have a unique key prop".
This adds a shared getFlattenedChildKey helper. Elements keep the key from flattening. Primitives are keyed by position as primitive-${index}, which can't collide with element keys: those always contain a . (.0, .$custom, 0..1) on both the React 16–18 and React 19+ flattening paths. ControlGroup already fell back to the index and now uses the same helper. Grid-variant ColumnLayout renders through Grid, so it's covered too.
Related links, issue #, if available: AWSUI-62564
How has this been tested?
Unit tests for the helper on both flattening paths, checking that keys are unique for mixed element, string, and number children.
Regression tests for SpaceBetween and Grid that assert nothing is logged to console.error. Both fail without the fix.
Review checklist
The following items are to be evaluated by the author(s) and the reviewer(s).
Correctness
Changes include appropriate documentation updates.
Changes are backward-compatible if not indicated, see CONTRIBUTING.md.
Changes do not include unsupported browser features, see CONTRIBUTING.md.
✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.10%. Comparing base (8ad64bc) to head (87a512c). ⚠️ Report is 23 commits behind head on main.
The reason will be displayed to describe this comment to others. Learn more.
Fair point: overriding React.version only switches the flattenChildren branch, and the test still runs React 16 or 18's Children.toArray, so it isn't testing React 19. I dropped the version loop, so the helper test no longer overrides React.version. The SpaceBetween and Grid tests cover the component behavior.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Keyed portals receive unstable positional keys on the React 19+ path, so reordering or inserting siblings can remount their contents and lose state or focus.
This test only exercises the legacy flattening path: the preceding React 16–18 suite leaves React.version set to 18.2.0, and this separate suite never overrides it. The mixed-child key behavior on the React 19+ Children.toArray path therefore remains untested, despite the stated coverage of both paths. Parameterize this test over the two mocked versions and restore the version afterward; no React 19 installation is needed.
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
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.
Description
SpaceBetween, Grid, and flexible ColumnLayout wrap each flattened child in a
<div>keyed by the child's key.flattenChildrenpasses strings and numbers through without a key, so their wrappers gotkey={undefined}. Any of these components with a text child next to an element, such as<SpaceBetween><Box>...</Box>{t('...')}</SpaceBetween>, logged "Each child in a list should have a unique key prop".This adds a shared
getFlattenedChildKeyhelper. Elements keep the key from flattening. Primitives are keyed by position asprimitive-${index}, which can't collide with element keys: those always contain a.(.0,.$custom,0..1) on both the React 16–18 and React 19+ flattening paths. ControlGroup already fell back to the index and now uses the same helper. Grid-variant ColumnLayout renders through Grid, so it's covered too.Related links, issue #, if available: AWSUI-62564
How has this been tested?
console.error. Both fail without the fix.Review checklist
The following items are to be evaluated by the author(s) and the reviewer(s).
Correctness
CONTRIBUTING.md.CONTRIBUTING.md.Security
checkSafeUrlfunction.Testing
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.