Skip to content

Commit 702fc98

Browse files
authored
Codemod act -> await act (4/?) (#26338)
Similar to the rationale for `waitFor` (see #26285), we should always await the result of an `act` call so that microtasks have a chance to fire. This only affects the internal `act` that we use in our repo, for now. In the public `act` API, we don't yet require this; however, we effectively will for any update that triggers suspense once `use` lands. So we likely will start warning in an upcoming minor.
1 parent 9fb2469 commit 702fc98

18 files changed

+907
-1075
lines changed

packages/react-debug-tools/src/__tests__/ReactHooksInspectionIntegration-test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,7 @@ describe('ReactHooksInspectionIntegration', () => {
984984
children: ['count: ', '1'],
985985
});
986986

987-
act(incrementCount);
987+
await act(async () => incrementCount());
988988
expect(renderer.toJSON()).toEqual({
989989
type: 'div',
990990
props: {},

packages/react-devtools-shared/src/__tests__/inspectedElement-test.js

+20-22
Original file line numberDiff line numberDiff line change
@@ -1069,8 +1069,8 @@ describe('InspectedElement', () => {
10691069
});
10701070

10711071
async function loadPath(path) {
1072-
TestUtilsAct(() => {
1073-
TestRendererAct(() => {
1072+
await TestUtilsAct(async () => {
1073+
await TestRendererAct(async () => {
10741074
inspectElementPath(path);
10751075
jest.runOnlyPendingTimers();
10761076
});
@@ -1224,8 +1224,8 @@ describe('InspectedElement', () => {
12241224
});
12251225

12261226
async function loadPath(path) {
1227-
TestUtilsAct(() => {
1228-
TestRendererAct(() => {
1227+
await TestUtilsAct(async () => {
1228+
await TestRendererAct(async () => {
12291229
inspectElementPath(path);
12301230
jest.runOnlyPendingTimers();
12311231
});
@@ -1306,8 +1306,8 @@ describe('InspectedElement', () => {
13061306
});
13071307

13081308
async function loadPath(path) {
1309-
TestUtilsAct(() => {
1310-
TestRendererAct(() => {
1309+
await TestUtilsAct(async () => {
1310+
await TestRendererAct(async () => {
13111311
inspectElementPath(path);
13121312
jest.runOnlyPendingTimers();
13131313
});
@@ -1375,8 +1375,8 @@ describe('InspectedElement', () => {
13751375
}
13761376
`);
13771377

1378-
TestRendererAct(() => {
1379-
TestUtilsAct(() => {
1378+
await TestRendererAct(async () => {
1379+
await TestUtilsAct(async () => {
13801380
legacyRender(
13811381
<Example
13821382
nestedObject={{
@@ -1469,8 +1469,8 @@ describe('InspectedElement', () => {
14691469
});
14701470

14711471
async function loadPath(path) {
1472-
TestUtilsAct(() => {
1473-
TestRendererAct(() => {
1472+
await TestUtilsAct(async () => {
1473+
await TestRendererAct(async () => {
14741474
inspectElementPath(path);
14751475
jest.runOnlyPendingTimers();
14761476
});
@@ -1513,8 +1513,8 @@ describe('InspectedElement', () => {
15131513
}
15141514
`);
15151515

1516-
TestRendererAct(() => {
1517-
TestUtilsAct(() => {
1516+
await TestRendererAct(async () => {
1517+
await TestUtilsAct(async () => {
15181518
legacyRender(
15191519
<Example
15201520
nestedObject={{
@@ -1596,8 +1596,8 @@ describe('InspectedElement', () => {
15961596
});
15971597

15981598
async function loadPath(path) {
1599-
TestUtilsAct(() => {
1600-
TestRendererAct(() => {
1599+
await TestUtilsAct(async () => {
1600+
await TestRendererAct(async () => {
16011601
inspectElementPath(path);
16021602
jest.runOnlyPendingTimers();
16031603
});
@@ -1618,7 +1618,7 @@ describe('InspectedElement', () => {
16181618
}
16191619
`);
16201620

1621-
TestUtilsAct(() => {
1621+
await TestUtilsAct(async () => {
16221622
legacyRender(
16231623
<Example
16241624
nestedObject={{
@@ -1640,11 +1640,9 @@ describe('InspectedElement', () => {
16401640
expect(inspectedElement.props).toMatchInlineSnapshot(`
16411641
{
16421642
"nestedObject": {
1643-
"a": {
1644-
"b": {
1645-
"value": 2,
1646-
},
1647-
"value": 2,
1643+
"a": Dehydrated {
1644+
"preview_short": {…},
1645+
"preview_long": {b: {…}, value: 2},
16481646
},
16491647
"value": 2,
16501648
},
@@ -2833,7 +2831,7 @@ describe('InspectedElement', () => {
28332831
};
28342832
const toggleError = async forceError => {
28352833
await withErrorsOrWarningsIgnored(['ErrorBoundary'], async () => {
2836-
await TestUtilsAct(() => {
2834+
await TestUtilsAct(async () => {
28372835
bridge.send('overrideError', {
28382836
id: targetErrorBoundaryID,
28392837
rendererID: store.getRendererIDForElement(targetErrorBoundaryID),
@@ -2842,7 +2840,7 @@ describe('InspectedElement', () => {
28422840
});
28432841
});
28442842

2845-
TestUtilsAct(() => {
2843+
await TestUtilsAct(async () => {
28462844
jest.runOnlyPendingTimers();
28472845
});
28482846
};

0 commit comments

Comments
 (0)