Remove consoleManagedByDevToolsDuringStrictMode (#31755)
This is enabled everywhere except the test renderers, which don't use it.
Ricky committed
Dec 13, 2024 at 11:05 UTC
4dff0e62b2320d8c97746a16c95efd9c9ad0bc07
9 files changed
+201
-449
packages/react-reconciler/src/ReactFiberDevToolsHook.js
+15
-28
@@ -19,7 +19,6 @@ type DevToolsProfilingHooks = any;
19
20
import {DidCapture} from './ReactFiberFlags';
21
import {
22
- consoleManagedByDevToolsDuringStrictMode,
22
enableProfilerTimer,
23
enableSchedulingProfiler,
24
} from 'shared/ReactFeatureFlags';
@@ -38,7 +37,6 @@ import {
37
unstable_setDisableYieldValue,
38
} from './Scheduler';
39
import {setSuppressWarning} from 'shared/consoleWithStackDev';
41
-import {disableLogs, reenableLogs} from 'shared/ConsolePatchingDev';
40
41
declare const __REACT_DEVTOOLS_GLOBAL_HOOK__: Object | void;
42
@@ -188,36 +186,25 @@ export function onCommitUnmount(fiber: Fiber) {
186
}
187
188
export function setIsStrictModeForDevtools(newIsStrictMode: boolean) {
191
- if (consoleManagedByDevToolsDuringStrictMode) {
192
- if (typeof log === 'function') {
193
- // We're in a test because Scheduler.log only exists
194
- // in SchedulerMock. To reduce the noise in strict mode tests,
195
- // suppress warnings and disable scheduler yielding during the double render
196
- unstable_setDisableYieldValue(newIsStrictMode);
197
- setSuppressWarning(newIsStrictMode);
198
- }
189
+ if (typeof log === 'function') {
190
+ // We're in a test because Scheduler.log only exists
191
+ // in SchedulerMock. To reduce the noise in strict mode tests,
192
+ // suppress warnings and disable scheduler yielding during the double render
193
+ unstable_setDisableYieldValue(newIsStrictMode);
194
+ setSuppressWarning(newIsStrictMode);
195
+ }
196
200
- if (injectedHook && typeof injectedHook.setStrictMode === 'function') {
201
- try {
202
- injectedHook.setStrictMode(rendererID, newIsStrictMode);
203
- } catch (err) {
204
- if (__DEV__) {
205
- if (!hasLoggedError) {
206
- hasLoggedError = true;
207
- console.error(
208
- 'React instrumentation encountered an error: %s',
209
- err,
210
- );
211
- }
197
+ if (injectedHook && typeof injectedHook.setStrictMode === 'function') {
198
+ try {
199
+ injectedHook.setStrictMode(rendererID, newIsStrictMode);
200
+ } catch (err) {
201
+ if (__DEV__) {
202
+ if (!hasLoggedError) {
203
+ hasLoggedError = true;
204
+ console.error('React instrumentation encountered an error: %s', err);
205
}
206
}
207
}
215
- } else {
216
- if (newIsStrictMode) {
217
- disableLogs();
218
- } else {
219
- reenableLogs();
220
- }
208
}
209
}
210
packages/react/src/__tests__/ReactStrictMode-test.js
+186
-410
@@ -20,8 +20,6 @@ let useState;
20
let useReducer;
21
let assertConsoleErrorDev;
22
23
-const ReactFeatureFlags = require('shared/ReactFeatureFlags');
24
-
23
describe('ReactStrictMode', () => {
24
beforeEach(() => {
25
jest.resetModules();
@@ -1111,450 +1109,228 @@ describe('context legacy', () => {
1109
console.log.mockRestore();
1110
});
1111
1114
- if (ReactFeatureFlags.consoleManagedByDevToolsDuringStrictMode) {
1115
- it('does not disable logs for class double render', async () => {
1116
- let count = 0;
1117
- class Foo extends React.Component {
1118
- render() {
1119
- count++;
1120
- console.log('foo ' + count);
1121
- return null;
1122
- }
1112
+ it('does not disable logs for class double render', async () => {
1113
+ let count = 0;
1114
+ class Foo extends React.Component {
1115
+ render() {
1116
+ count++;
1117
+ console.log('foo ' + count);
1118
+ return null;
1119
}
1120
+ }
1121
1125
- const container = document.createElement('div');
1126
- const root = ReactDOMClient.createRoot(container);
1127
- await act(() => {
1128
- root.render(
1129
- <React.StrictMode>
1130
- <Foo />
1131
- </React.StrictMode>,
1132
- );
1133
- });
1134
- expect(count).toBe(__DEV__ ? 2 : 1);
1135
- expect(console.log).toBeCalledTimes(__DEV__ ? 2 : 1);
1136
- // Note: we should display the first log because otherwise
1137
- // there is a risk of suppressing warnings when they happen,
1138
- // and on the next render they'd get deduplicated and ignored.
1139
- expect(console.log).toBeCalledWith('foo 1');
1122
+ const container = document.createElement('div');
1123
+ const root = ReactDOMClient.createRoot(container);
1124
+ await act(() => {
1125
+ root.render(
1126
+ <React.StrictMode>
1127
+ <Foo />
1128
+ </React.StrictMode>,
1129
+ );
1130
});
1131
+ expect(count).toBe(__DEV__ ? 2 : 1);
1132
+ expect(console.log).toBeCalledTimes(__DEV__ ? 2 : 1);
1133
+ // Note: we should display the first log because otherwise
1134
+ // there is a risk of suppressing warnings when they happen,
1135
+ // and on the next render they'd get deduplicated and ignored.
1136
+ expect(console.log).toBeCalledWith('foo 1');
1137
+ });
1138
1142
- it('does not disable logs for class double ctor', async () => {
1143
- let count = 0;
1144
- class Foo extends React.Component {
1145
- constructor(props) {
1146
- super(props);
1147
- count++;
1148
- console.log('foo ' + count);
1149
- }
1150
- render() {
1151
- return null;
1152
- }
1139
+ it('does not disable logs for class double ctor', async () => {
1140
+ let count = 0;
1141
+ class Foo extends React.Component {
1142
+ constructor(props) {
1143
+ super(props);
1144
+ count++;
1145
+ console.log('foo ' + count);
1146
}
1154
-
1155
- const container = document.createElement('div');
1156
- const root = ReactDOMClient.createRoot(container);
1157
- await act(() => {
1158
- root.render(
1159
- <React.StrictMode>
1160
- <Foo />
1161
- </React.StrictMode>,
1162
- );
1163
- });
1164
- expect(count).toBe(__DEV__ ? 2 : 1);
1165
- expect(console.log).toBeCalledTimes(__DEV__ ? 2 : 1);
1166
- // Note: we should display the first log because otherwise
1167
- // there is a risk of suppressing warnings when they happen,
1168
- // and on the next render they'd get deduplicated and ignored.
1169
- expect(console.log).toBeCalledWith('foo 1');
1170
- });
1171
-
1172
- it('does not disable logs for class double getDerivedStateFromProps', async () => {
1173
- let count = 0;
1174
- class Foo extends React.Component {
1175
- state = {};
1176
- static getDerivedStateFromProps() {
1177
- count++;
1178
- console.log('foo ' + count);
1179
- return {};
1180
- }
1181
- render() {
1182
- return null;
1183
- }
1147
+ render() {
1148
+ return null;
1149
}
1150
+ }
1151
1186
- const container = document.createElement('div');
1187
- const root = ReactDOMClient.createRoot(container);
1188
- await act(() => {
1189
- root.render(
1190
- <React.StrictMode>
1191
- <Foo />
1192
- </React.StrictMode>,
1193
- );
1194
- });
1195
- expect(count).toBe(__DEV__ ? 2 : 1);
1196
- expect(console.log).toBeCalledTimes(__DEV__ ? 2 : 1);
1197
- // Note: we should display the first log because otherwise
1198
- // there is a risk of suppressing warnings when they happen,
1199
- // and on the next render they'd get deduplicated and ignored.
1200
- expect(console.log).toBeCalledWith('foo 1');
1152
+ const container = document.createElement('div');
1153
+ const root = ReactDOMClient.createRoot(container);
1154
+ await act(() => {
1155
+ root.render(
1156
+ <React.StrictMode>
1157
+ <Foo />
1158
+ </React.StrictMode>,
1159
+ );
1160
});
1161
+ expect(count).toBe(__DEV__ ? 2 : 1);
1162
+ expect(console.log).toBeCalledTimes(__DEV__ ? 2 : 1);
1163
+ // Note: we should display the first log because otherwise
1164
+ // there is a risk of suppressing warnings when they happen,
1165
+ // and on the next render they'd get deduplicated and ignored.
1166
+ expect(console.log).toBeCalledWith('foo 1');
1167
+ });
1168
1203
- it('does not disable logs for class double shouldComponentUpdate', async () => {
1204
- let count = 0;
1205
- class Foo extends React.Component {
1206
- state = {};
1207
- shouldComponentUpdate() {
1208
- count++;
1209
- console.log('foo ' + count);
1210
- return {};
1211
- }
1212
- render() {
1213
- return null;
1214
- }
1169
+ it('does not disable logs for class double getDerivedStateFromProps', async () => {
1170
+ let count = 0;
1171
+ class Foo extends React.Component {
1172
+ state = {};
1173
+ static getDerivedStateFromProps() {
1174
+ count++;
1175
+ console.log('foo ' + count);
1176
+ return {};
1177
}
1216
-
1217
- const container = document.createElement('div');
1218
- const root = ReactDOMClient.createRoot(container);
1219
- await act(() => {
1220
- root.render(
1221
- <React.StrictMode>
1222
- <Foo />
1223
- </React.StrictMode>,
1224
- );
1225
- });
1226
- await act(() => {
1227
- root.render(
1228
- <React.StrictMode>
1229
- <Foo />
1230
- </React.StrictMode>,
1231
- );
1232
- });
1233
-
1234
- expect(count).toBe(__DEV__ ? 2 : 1);
1235
- expect(console.log).toBeCalledTimes(__DEV__ ? 2 : 1);
1236
- // Note: we should display the first log because otherwise
1237
- // there is a risk of suppressing warnings when they happen,
1238
- // and on the next render they'd get deduplicated and ignored.
1239
- expect(console.log).toBeCalledWith('foo 1');
1240
- });
1241
-
1242
- it('does not disable logs for class state updaters', async () => {
1243
- let inst;
1244
- let count = 0;
1245
- class Foo extends React.Component {
1246
- state = {};
1247
- render() {
1248
- inst = this;
1249
- return null;
1250
- }
1178
+ render() {
1179
+ return null;
1180
}
1181
+ }
1182
1253
- const container = document.createElement('div');
1254
- const root = ReactDOMClient.createRoot(container);
1255
- await act(() => {
1256
- root.render(
1257
- <React.StrictMode>
1258
- <Foo />
1259
- </React.StrictMode>,
1260
- );
1261
- });
1262
- await act(() => {
1263
- inst.setState(() => {
1264
- count++;
1265
- console.log('foo ' + count);
1266
- return {};
1267
- });
1268
- });
1269
-
1270
- expect(count).toBe(__DEV__ ? 2 : 1);
1271
- expect(console.log).toBeCalledTimes(__DEV__ ? 2 : 1);
1272
- // Note: we should display the first log because otherwise
1273
- // there is a risk of suppressing warnings when they happen,
1274
- // and on the next render they'd get deduplicated and ignored.
1275
- expect(console.log).toBeCalledWith('foo 1');
1183
+ const container = document.createElement('div');
1184
+ const root = ReactDOMClient.createRoot(container);
1185
+ await act(() => {
1186
+ root.render(
1187
+ <React.StrictMode>
1188
+ <Foo />
1189
+ </React.StrictMode>,
1190
+ );
1191
});
1192
+ expect(count).toBe(__DEV__ ? 2 : 1);
1193
+ expect(console.log).toBeCalledTimes(__DEV__ ? 2 : 1);
1194
+ // Note: we should display the first log because otherwise
1195
+ // there is a risk of suppressing warnings when they happen,
1196
+ // and on the next render they'd get deduplicated and ignored.
1197
+ expect(console.log).toBeCalledWith('foo 1');
1198
+ });
1199
1278
- it('does not disable logs for function double render', async () => {
1279
- let count = 0;
1280
- function Foo() {
1200
+ it('does not disable logs for class double shouldComponentUpdate', async () => {
1201
+ let count = 0;
1202
+ class Foo extends React.Component {
1203
+ state = {};
1204
+ shouldComponentUpdate() {
1205
count++;
1206
console.log('foo ' + count);
1283
- return null;
1207
+ return {};
1208
}
1285
-
1286
- const container = document.createElement('div');
1287
- const root = ReactDOMClient.createRoot(container);
1288
- await act(() => {
1289
- root.render(
1290
- <React.StrictMode>
1291
- <Foo />
1292
- </React.StrictMode>,
1293
- );
1294
- });
1295
- expect(count).toBe(__DEV__ ? 2 : 1);
1296
- expect(console.log).toBeCalledTimes(__DEV__ ? 2 : 1);
1297
- // Note: we should display the first log because otherwise
1298
- // there is a risk of suppressing warnings when they happen,
1299
- // and on the next render they'd get deduplicated and ignored.
1300
- expect(console.log).toBeCalledWith('foo 1');
1301
- });
1302
-
1303
- it('does not disable logs for effect double invoke', async () => {
1304
- let create = 0;
1305
- let cleanup = 0;
1306
- function Foo() {
1307
- React.useEffect(() => {
1308
- create++;
1309
- console.log('foo create ' + create);
1310
- return () => {
1311
- cleanup++;
1312
- console.log('foo cleanup ' + cleanup);
1313
- };
1314
- });
1209
+ render() {
1210
return null;
1211
}
1212
+ }
1213
1318
- const container = document.createElement('div');
1319
- const root = ReactDOMClient.createRoot(container);
1320
- await act(() => {
1321
- root.render(
1322
- <React.StrictMode>
1323
- <Foo />
1324
- </React.StrictMode>,
1325
- );
1326
- });
1327
- expect(create).toBe(__DEV__ ? 2 : 1);
1328
- expect(cleanup).toBe(__DEV__ ? 1 : 0);
1329
- expect(console.log).toBeCalledTimes(__DEV__ ? 3 : 1);
1330
- // Note: we should display the first log because otherwise
1331
- // there is a risk of suppressing warnings when they happen,
1332
- // and on the next render they'd get deduplicated and ignored.
1333
- expect(console.log).toBeCalledWith('foo create 1');
1334
- if (__DEV__) {
1335
- expect(console.log).toBeCalledWith('foo cleanup 1');
1336
- }
1214
+ const container = document.createElement('div');
1215
+ const root = ReactDOMClient.createRoot(container);
1216
+ await act(() => {
1217
+ root.render(
1218
+ <React.StrictMode>
1219
+ <Foo />
1220
+ </React.StrictMode>,
1221
+ );
1222
});
1338
- } else {
1339
- it('disable logs for class double render', async () => {
1340
- let count = 0;
1341
- class Foo extends React.Component {
1342
- render() {
1343
- count++;
1344
- console.log('foo ' + count);
1345
- return null;
1346
- }
1347
- }
1348
-
1349
- const container = document.createElement('div');
1350
- const root = ReactDOMClient.createRoot(container);
1351
- await act(() => {
1352
- root.render(
1353
- <React.StrictMode>
1354
- <Foo />
1355
- </React.StrictMode>,
1356
- );
1357
- });
1358
- expect(count).toBe(__DEV__ ? 2 : 1);
1359
- expect(console.log).toBeCalledTimes(1);
1360
- // Note: we should display the first log because otherwise
1361
- // there is a risk of suppressing warnings when they happen,
1362
- // and on the next render they'd get deduplicated and ignored.
1363
- expect(console.log).toBeCalledWith('foo 1');
1223
+ await act(() => {
1224
+ root.render(
1225
+ <React.StrictMode>
1226
+ <Foo />
1227
+ </React.StrictMode>,
1228
+ );
1229
});
1230
1366
- it('disables logs for class double ctor', async () => {
1367
- let count = 0;
1368
- class Foo extends React.Component {
1369
- constructor(props) {
1370
- super(props);
1371
- count++;
1372
- console.log('foo ' + count);
1373
- }
1374
- render() {
1375
- return null;
1376
- }
1377
- }
1378
-
1379
- const container = document.createElement('div');
1380
- const root = ReactDOMClient.createRoot(container);
1381
- await act(() => {
1382
- root.render(
1383
- <React.StrictMode>
1384
- <Foo />
1385
- </React.StrictMode>,
1386
- );
1387
- });
1388
- expect(count).toBe(__DEV__ ? 2 : 1);
1389
- expect(console.log).toBeCalledTimes(1);
1390
- // Note: we should display the first log because otherwise
1391
- // there is a risk of suppressing warnings when they happen,
1392
- // and on the next render they'd get deduplicated and ignored.
1393
- expect(console.log).toBeCalledWith('foo 1');
1394
- });
1231
+ expect(count).toBe(__DEV__ ? 2 : 1);
1232
+ expect(console.log).toBeCalledTimes(__DEV__ ? 2 : 1);
1233
+ // Note: we should display the first log because otherwise
1234
+ // there is a risk of suppressing warnings when they happen,
1235
+ // and on the next render they'd get deduplicated and ignored.
1236
+ expect(console.log).toBeCalledWith('foo 1');
1237
+ });
1238
1396
- it('disable logs for class double getDerivedStateFromProps', async () => {
1397
- let count = 0;
1398
- class Foo extends React.Component {
1399
- state = {};
1400
- static getDerivedStateFromProps() {
1401
- count++;
1402
- console.log('foo ' + count);
1403
- return {};
1404
- }
1405
- render() {
1406
- return null;
1407
- }
1239
+ it('does not disable logs for class state updaters', async () => {
1240
+ let inst;
1241
+ let count = 0;
1242
+ class Foo extends React.Component {
1243
+ state = {};
1244
+ render() {
1245
+ inst = this;
1246
+ return null;
1247
}
1248
+ }
1249
1410
- const container = document.createElement('div');
1411
- const root = ReactDOMClient.createRoot(container);
1412
- await act(() => {
1413
- root.render(
1414
- <React.StrictMode>
1415
- <Foo />
1416
- </React.StrictMode>,
1417
- );
1418
- });
1419
- expect(count).toBe(__DEV__ ? 2 : 1);
1420
- expect(console.log).toBeCalledTimes(1);
1421
- // Note: we should display the first log because otherwise
1422
- // there is a risk of suppressing warnings when they happen,
1423
- // and on the next render they'd get deduplicated and ignored.
1424
- expect(console.log).toBeCalledWith('foo 1');
1250
+ const container = document.createElement('div');
1251
+ const root = ReactDOMClient.createRoot(container);
1252
+ await act(() => {
1253
+ root.render(
1254
+ <React.StrictMode>
1255
+ <Foo />
1256
+ </React.StrictMode>,
1257
+ );
1258
});
1426
-
1427
- it('disable logs for class double shouldComponentUpdate', async () => {
1428
- let count = 0;
1429
- class Foo extends React.Component {
1430
- state = {};
1431
- shouldComponentUpdate() {
1432
- count++;
1433
- console.log('foo ' + count);
1434
- return {};
1435
- }
1436
- render() {
1437
- return null;
1438
- }
1439
- }
1440
-
1441
- const container = document.createElement('div');
1442
- const root = ReactDOMClient.createRoot(container);
1443
- await act(() => {
1444
- root.render(
1445
- <React.StrictMode>
1446
- <Foo />
1447
- </React.StrictMode>,
1448
- );
1449
- });
1450
- await act(() => {
1451
- root.render(
1452
- <React.StrictMode>
1453
- <Foo />
1454
- </React.StrictMode>,
1455
- );
1259
+ await act(() => {
1260
+ inst.setState(() => {
1261
+ count++;
1262
+ console.log('foo ' + count);
1263
+ return {};
1264
});
1457
- expect(count).toBe(__DEV__ ? 2 : 1);
1458
- expect(console.log).toBeCalledTimes(1);
1459
- // Note: we should display the first log because otherwise
1460
- // there is a risk of suppressing warnings when they happen,
1461
- // and on the next render they'd get deduplicated and ignored.
1462
- expect(console.log).toBeCalledWith('foo 1');
1265
});
1266
1465
- it('disable logs for class state updaters', async () => {
1466
- let inst;
1467
- let count = 0;
1468
- class Foo extends React.Component {
1469
- state = {};
1470
- render() {
1471
- inst = this;
1472
- return null;
1473
- }
1474
- }
1267
+ expect(count).toBe(__DEV__ ? 2 : 1);
1268
+ expect(console.log).toBeCalledTimes(__DEV__ ? 2 : 1);
1269
+ // Note: we should display the first log because otherwise
1270
+ // there is a risk of suppressing warnings when they happen,
1271
+ // and on the next render they'd get deduplicated and ignored.
1272
+ expect(console.log).toBeCalledWith('foo 1');
1273
+ });
1274
1476
- const container = document.createElement('div');
1477
- const root = ReactDOMClient.createRoot(container);
1478
- await act(() => {
1479
- root.render(
1480
- <React.StrictMode>
1481
- <Foo />
1482
- </React.StrictMode>,
1483
- );
1484
- });
1485
- await act(() => {
1486
- inst.setState(() => {
1487
- count++;
1488
- console.log('foo ' + count);
1489
- return {};
1490
- });
1491
- });
1275
+ it('does not disable logs for function double render', async () => {
1276
+ let count = 0;
1277
+ function Foo() {
1278
+ count++;
1279
+ console.log('foo ' + count);
1280
+ return null;
1281
+ }
1282
1493
- expect(count).toBe(__DEV__ ? 2 : 1);
1494
- expect(console.log).toBeCalledTimes(1);
1495
- // Note: we should display the first log because otherwise
1496
- // there is a risk of suppressing warnings when they happen,
1497
- // and on the next render they'd get deduplicated and ignored.
1498
- expect(console.log).toBeCalledWith('foo 1');
1283
+ const container = document.createElement('div');
1284
+ const root = ReactDOMClient.createRoot(container);
1285
+ await act(() => {
1286
+ root.render(
1287
+ <React.StrictMode>
1288
+ <Foo />
1289
+ </React.StrictMode>,
1290
+ );
1291
});
1292
+ expect(count).toBe(__DEV__ ? 2 : 1);
1293
+ expect(console.log).toBeCalledTimes(__DEV__ ? 2 : 1);
1294
+ // Note: we should display the first log because otherwise
1295
+ // there is a risk of suppressing warnings when they happen,
1296
+ // and on the next render they'd get deduplicated and ignored.
1297
+ expect(console.log).toBeCalledWith('foo 1');
1298
+ });
1299
1501
- it('disable logs for function double render', async () => {
1502
- let count = 0;
1503
- function Foo() {
1504
- count++;
1505
- console.log('foo ' + count);
1506
- return null;
1507
- }
1508
-
1509
- const container = document.createElement('div');
1510
- const root = ReactDOMClient.createRoot(container);
1511
- await act(() => {
1512
- root.render(
1513
- <React.StrictMode>
1514
- <Foo />
1515
- </React.StrictMode>,
1516
- );
1300
+ it('does not disable logs for effect double invoke', async () => {
1301
+ let create = 0;
1302
+ let cleanup = 0;
1303
+ function Foo() {
1304
+ React.useEffect(() => {
1305
+ create++;
1306
+ console.log('foo create ' + create);
1307
+ return () => {
1308
+ cleanup++;
1309
+ console.log('foo cleanup ' + cleanup);
1310
+ };
1311
});
1518
- expect(count).toBe(__DEV__ ? 2 : 1);
1519
- expect(console.log).toBeCalledTimes(1);
1520
- // Note: we should display the first log because otherwise
1521
- // there is a risk of suppressing warnings when they happen,
1522
- // and on the next render they'd get deduplicated and ignored.
1523
- expect(console.log).toBeCalledWith('foo 1');
1524
- });
1525
-
1526
- it('disable logs for effect double invoke', async () => {
1527
- let create = 0;
1528
- let cleanup = 0;
1529
- function Foo() {
1530
- React.useEffect(() => {
1531
- create++;
1532
- console.log('foo create ' + create);
1533
- return () => {
1534
- cleanup++;
1535
- console.log('foo cleanup ' + cleanup);
1536
- };
1537
- });
1538
- return null;
1539
- }
1312
+ return null;
1313
+ }
1314
1541
- const container = document.createElement('div');
1542
- const root = ReactDOMClient.createRoot(container);
1543
- await act(() => {
1544
- root.render(
1545
- <React.StrictMode>
1546
- <Foo />
1547
- </React.StrictMode>,
1548
- );
1549
- });
1550
- expect(create).toBe(__DEV__ ? 2 : 1);
1551
- expect(cleanup).toBe(__DEV__ ? 1 : 0);
1552
- expect(console.log).toBeCalledTimes(1);
1553
- // Note: we should display the first log because otherwise
1554
- // there is a risk of suppressing warnings when they happen,
1555
- // and on the next render they'd get deduplicated and ignored.
1556
- expect(console.log).toBeCalledWith('foo create 1');
1315
+ const container = document.createElement('div');
1316
+ const root = ReactDOMClient.createRoot(container);
1317
+ await act(() => {
1318
+ root.render(
1319
+ <React.StrictMode>
1320
+ <Foo />
1321
+ </React.StrictMode>,
1322
+ );
1323
});
1558
- }
1324
+ expect(create).toBe(__DEV__ ? 2 : 1);
1325
+ expect(cleanup).toBe(__DEV__ ? 1 : 0);
1326
+ expect(console.log).toBeCalledTimes(__DEV__ ? 3 : 1);
1327
+ // Note: we should display the first log because otherwise
1328
+ // there is a risk of suppressing warnings when they happen,
1329
+ // and on the next render they'd get deduplicated and ignored.
1330
+ expect(console.log).toBeCalledWith('foo create 1');
1331
+ if (__DEV__) {
1332
+ expect(console.log).toBeCalledWith('foo cleanup 1');
1333
+ }
1334
+ });
1335
});
1336
});
packages/shared/ReactFeatureFlags.js
-2
@@ -297,6 +297,4 @@ export const enableUpdaterTracking = __PROFILE__;
297
// Internal only.
298
export const enableGetInspectorDataForInstanceInProduction = false;
299
300
-export const consoleManagedByDevToolsDuringStrictMode = true;
301
-
300
export const enableDO_NOT_USE_disableStrictPassiveEffect = false;
packages/shared/forks/ReactFeatureFlags.native-fb.js
-1
@@ -32,7 +32,6 @@ export const {
32
} = dynamicFlags;
33
34
// The rest of the flags are static for better dead code elimination.
35
-export const consoleManagedByDevToolsDuringStrictMode = true;
35
export const debugRenderPhaseSideEffectsForStrictMode = __DEV__;
36
export const disableClientCache = true;
37
export const disableCommentsAsDOMContainers = true;
packages/shared/forks/ReactFeatureFlags.native-oss.js
-1
@@ -20,7 +20,6 @@ export const debugRenderPhaseSideEffectsForStrictMode = __DEV__;
20
// All other flags
21
// -----------------------------------------------------------------------------
22
export const alwaysThrottleRetries = false;
23
-export const consoleManagedByDevToolsDuringStrictMode = true;
23
export const disableClientCache = true;
24
export const disableCommentsAsDOMContainers = true;
25
export const disableDefaultPropsExceptForClasses = true;
packages/shared/forks/ReactFeatureFlags.test-renderer.js
-2
@@ -61,8 +61,6 @@ export const enableLazyContextPropagation = true;
61
export const enableContextProfiling = false;
62
export const enableLegacyHidden = false;
63
64
-export const consoleManagedByDevToolsDuringStrictMode = false;
65
-
64
export const enableTransitionTracing = false;
65
66
export const useModernStrictMode = false;
packages/shared/forks/ReactFeatureFlags.test-renderer.native-fb.js
-1
@@ -11,7 +11,6 @@ import typeof * as FeatureFlagsType from 'shared/ReactFeatureFlags';
11
import typeof * as ExportsType from './ReactFeatureFlags.test-renderer';
12
13
export const alwaysThrottleRetries = false;
14
-export const consoleManagedByDevToolsDuringStrictMode = false;
14
export const debugRenderPhaseSideEffectsForStrictMode = false;
15
export const disableClientCache = true;
16
export const disableCommentsAsDOMContainers = true;
packages/shared/forks/ReactFeatureFlags.test-renderer.www.js
-2
@@ -63,8 +63,6 @@ export const enableLazyContextPropagation = true;
63
export const enableContextProfiling = false;
64
export const enableLegacyHidden = false;
65
66
-export const consoleManagedByDevToolsDuringStrictMode = false;
67
-
66
export const enableTransitionTracing = false;
67
68
export const useModernStrictMode = false;
packages/shared/forks/ReactFeatureFlags.www.js
-2
@@ -106,8 +106,6 @@ export const enableComponentStackLocations = true;
106
107
export const disableTextareaChildren = __EXPERIMENTAL__;
108
109
-export const consoleManagedByDevToolsDuringStrictMode = true;
110
-
109
export const enableFizzExternalRuntime = true;
110
111
export const passChildrenWhenCloningPersistedNodes = false;