@@ -2922,6 +2922,41 @@ function warnForMissingKey(request: Request, task: Task, child: mixed): void {
2922
2922
}
2923
2923
didWarnForKey . add ( parentStackFrame ) ;
2924
2924
2925
+ const componentName = getComponentNameFromType ( child . type ) ;
2926
+ const childOwner = child . _owner ;
2927
+ const parentOwner = parentStackFrame . owner ;
2928
+
2929
+ let currentComponentErrorInfo = '' ;
2930
+ if ( parentOwner && typeof parentOwner . tag === 'number' ) {
2931
+ const name = getComponentNameFromType ( ( parentOwner : any ) . type ) ;
2932
+ if ( name ) {
2933
+ currentComponentErrorInfo =
2934
+ '\n\nCheck the render method of `' + name + '`.' ;
2935
+ }
2936
+ }
2937
+ if ( ! currentComponentErrorInfo ) {
2938
+ if ( componentName ) {
2939
+ currentComponentErrorInfo = `\n\nCheck the top-level render call using <${ componentName } >.` ;
2940
+ }
2941
+ }
2942
+
2943
+ // Usually the current owner is the offender, but if it accepts children as a
2944
+ // property, it may be the creator of the child that's responsible for
2945
+ // assigning it a key.
2946
+ let childOwnerAppendix = '' ;
2947
+ if ( childOwner != null && parentOwner !== childOwner ) {
2948
+ let ownerName = null ;
2949
+ if ( typeof childOwner . tag === 'number' ) {
2950
+ ownerName = getComponentNameFromType ( ( childOwner : any ) . type ) ;
2951
+ } else if ( typeof childOwner . name === 'string' ) {
2952
+ ownerName = childOwner . name ;
2953
+ }
2954
+ if ( ownerName ) {
2955
+ // Give the component that originally created this child.
2956
+ childOwnerAppendix = ` It was passed a child from ${ ownerName } .` ;
2957
+ }
2958
+ }
2959
+
2925
2960
// We create a fake component stack for the child to log the stack trace from.
2926
2961
const stackFrame = createComponentStackFromType (
2927
2962
task ,
@@ -2933,8 +2968,8 @@ function warnForMissingKey(request: Request, task: Task, child: mixed): void {
2933
2968
console . error (
2934
2969
'Each child in a list should have a unique "key" prop.' +
2935
2970
'%s%s See https://react.dev/link/warning-keys for more information.' ,
2936
- '' ,
2937
- '' ,
2971
+ currentComponentErrorInfo ,
2972
+ childOwnerAppendix ,
2938
2973
) ;
2939
2974
task . componentStack = stackFrame . parent ;
2940
2975
}
0 commit comments