@@ -868,7 +868,105 @@ describe('ReactChildren', () => {
868868 ] ) ;
869869 } ) ;
870870
871- it ( 'should warn for flattened children lists' , async ( ) => {
871+ it ( 'warns for mapped list children without keys' , async ( ) => {
872+ function ComponentRenderingMappedChildren ( { children} ) {
873+ return (
874+ < div >
875+ { React . Children . map ( children , child => (
876+ < div />
877+ ) ) }
878+ </ div >
879+ ) ;
880+ }
881+
882+ const container = document . createElement ( 'div' ) ;
883+ const root = ReactDOMClient . createRoot ( container ) ;
884+ await expect ( async ( ) => {
885+ await act ( ( ) => {
886+ root . render (
887+ < ComponentRenderingMappedChildren >
888+ { [ < div /> ] }
889+ </ ComponentRenderingMappedChildren > ,
890+ ) ;
891+ } ) ;
892+ } ) . toErrorDev ( [
893+ 'Warning: Each child in a list should have a unique "key" prop.' ,
894+ ] ) ;
895+ } ) ;
896+
897+ it ( 'does not warn for mapped static children without keys' , async ( ) => {
898+ function ComponentRenderingMappedChildren ( { children} ) {
899+ return (
900+ < div >
901+ { React . Children . map ( children , child => (
902+ < div />
903+ ) ) }
904+ </ div >
905+ ) ;
906+ }
907+
908+ const container = document . createElement ( 'div' ) ;
909+ const root = ReactDOMClient . createRoot ( container ) ;
910+ await expect ( async ( ) => {
911+ await act ( ( ) => {
912+ root . render (
913+ < ComponentRenderingMappedChildren >
914+ < div />
915+ < div />
916+ </ ComponentRenderingMappedChildren > ,
917+ ) ;
918+ } ) ;
919+ } ) . toErrorDev ( [ ] ) ;
920+ } ) ;
921+
922+ it ( 'warns for cloned list children without keys' , async ( ) => {
923+ function ComponentRenderingClonedChildren ( { children} ) {
924+ return (
925+ < div >
926+ { React . Children . map ( children , child => React . cloneElement ( child ) ) }
927+ </ div >
928+ ) ;
929+ }
930+
931+ const container = document . createElement ( 'div' ) ;
932+ const root = ReactDOMClient . createRoot ( container ) ;
933+ await expect ( async ( ) => {
934+ await act ( ( ) => {
935+ root . render (
936+ < ComponentRenderingClonedChildren >
937+ { [ < div /> ] }
938+ </ ComponentRenderingClonedChildren > ,
939+ ) ;
940+ } ) ;
941+ } ) . toErrorDev ( [
942+ 'Warning: Each child in a list should have a unique "key" prop.' ,
943+ ] ) ;
944+ } ) ;
945+
946+ it ( 'does not warn for cloned static children without keys' , async ( ) => {
947+ function ComponentRenderingClonedChildren ( { children} ) {
948+ return (
949+ < div >
950+ { React . Children . map ( children , child => React . cloneElement ( child ) ) }
951+ </ div >
952+ ) ;
953+ }
954+
955+ const container = document . createElement ( 'div' ) ;
956+ const root = ReactDOMClient . createRoot ( container ) ;
957+ await expect ( async ( ) => {
958+ await act ( ( ) => {
959+ root . render (
960+ < ComponentRenderingClonedChildren >
961+ < div />
962+ < div />
963+ </ ComponentRenderingClonedChildren > ,
964+ ) ;
965+ } ) ;
966+ } ) . toErrorDev ( [ ] ) ;
967+ } ) ;
968+
969+ it ( 'warns for flattened list children without keys' , async ( ) => {
872970 function ComponentRenderingFlattenedChildren ( { children} ) {
873971 return < div > { React . Children . toArray ( children ) } </ div > ;
874972 }
@@ -888,7 +986,7 @@ describe('ReactChildren', () => {
888986 ] ) ;
889987 } ) ;
890988
891- it ( 'does not warn for flattened positional children' , async ( ) => {
989+ it ( 'does not warn for flattened static children without keys ' , async ( ) => {
892990 function ComponentRenderingFlattenedChildren ( { children} ) {
893991 return < div > { React . Children . toArray ( children ) } </ div > ;
894992 }
0 commit comments