@@ -80,6 +80,8 @@ import {
8080 createHints ,
8181 initAsyncDebugInfo ,
8282 parseStackTrace ,
83+ supportsComponentStorage ,
84+ componentStorage ,
8385} from './ReactFlightServerConfig' ;
8486
8587import {
@@ -1035,12 +1037,38 @@ function renderFunctionComponent<Props>(
10351037 }
10361038 }
10371039 prepareToUseHooksForComponent ( prevThenableState , componentDebugInfo ) ;
1038- result = callComponentInDEV (
1039- Component ,
1040- props ,
1041- componentDebugInfo ,
1042- task . debugTask ,
1043- ) ;
1040+ if ( supportsComponentStorage ) {
1041+ // Run the component in an Async Context that tracks the current owner.
1042+ if ( enableOwnerStacks && task . debugTask ) {
1043+ result = task . debugTask . run (
1044+ // $FlowFixMe[method-unbinding]
1045+ componentStorage . run . bind (
1046+ componentStorage ,
1047+ componentDebugInfo ,
1048+ callComponentInDEV ,
1049+ Component ,
1050+ props ,
1051+ componentDebugInfo ,
1052+ ) ,
1053+ ) ;
1054+ } else {
1055+ result = componentStorage . run (
1056+ componentDebugInfo ,
1057+ callComponentInDEV ,
1058+ Component ,
1059+ props ,
1060+ componentDebugInfo ,
1061+ ) ;
1062+ }
1063+ } else {
1064+ if ( enableOwnerStacks && task . debugTask ) {
1065+ result = task . debugTask . run (
1066+ callComponentInDEV . bind ( null , Component , props , componentDebugInfo ) ,
1067+ ) ;
1068+ } else {
1069+ result = callComponentInDEV ( Component , props , componentDebugInfo ) ;
1070+ }
1071+ }
10441072 } else {
10451073 prepareToUseHooksForComponent ( prevThenableState , null ) ;
10461074 // The secondArg is always undefined in Server Components since refs error early.
@@ -1222,19 +1250,47 @@ function warnForMissingKey(
12221250
12231251 // Call with the server component as the currently rendering component
12241252 // for context.
1225- callComponentInDEV (
1226- ( ) => {
1227- console . error (
1228- 'Each child in a list should have a unique "key" prop.' +
1229- '%s%s See https://react.dev/link/warning-keys for more information.' ,
1230- '' ,
1231- '' ,
1253+ const logKeyError = ( ) => {
1254+ console . error (
1255+ 'Each child in a list should have a unique "key" prop.' +
1256+ '%s%s See https://react.dev/link/warning-keys for more information.' ,
1257+ '' ,
1258+ '' ,
1259+ ) ;
1260+ } ;
1261+
1262+ if (supportsComponentStorage) {
1263+ // Run the component in an Async Context that tracks the current owner.
1264+ if ( enableOwnerStacks && debugTask ) {
1265+ debugTask . run (
1266+ // $FlowFixMe[method-unbinding]
1267+ componentStorage . run . bind (
1268+ componentStorage ,
1269+ componentDebugInfo ,
1270+ callComponentInDEV ,
1271+ logKeyError ,
1272+ null ,
1273+ componentDebugInfo ,
1274+ ) ,
12321275 ) ;
1233- } ,
1234- null,
1235- componentDebugInfo,
1236- debugTask,
1237- );
1276+ } else {
1277+ componentStorage . run (
1278+ componentDebugInfo ,
1279+ callComponentInDEV ,
1280+ logKeyError ,
1281+ null ,
1282+ componentDebugInfo ,
1283+ ) ;
1284+ }
1285+ } else {
1286+ if ( enableOwnerStacks && debugTask ) {
1287+ debugTask . run (
1288+ callComponentInDEV . bind ( null , logKeyError , null , componentDebugInfo ) ,
1289+ ) ;
1290+ } else {
1291+ callComponentInDEV ( logKeyError , null , componentDebugInfo ) ;
1292+ }
1293+ }
12381294 }
12391295}
12401296
0 commit comments