@@ -80,6 +80,8 @@ import {
80
80
createHints ,
81
81
initAsyncDebugInfo ,
82
82
parseStackTrace ,
83
+ supportsComponentStorage ,
84
+ componentStorage ,
83
85
} from './ReactFlightServerConfig' ;
84
86
85
87
import {
@@ -1035,12 +1037,38 @@ function renderFunctionComponent<Props>(
1035
1037
}
1036
1038
}
1037
1039
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
+ }
1044
1072
} else {
1045
1073
prepareToUseHooksForComponent ( prevThenableState , null ) ;
1046
1074
// The secondArg is always undefined in Server Components since refs error early.
@@ -1222,19 +1250,47 @@ function warnForMissingKey(
1222
1250
1223
1251
// Call with the server component as the currently rendering component
1224
1252
// 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
+ ) ,
1232
1275
) ;
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
+ }
1238
1294
}
1239
1295
}
1240
1296
0 commit comments