Skip to content

Commit 62cd5af

Browse files
authored
Codemod redundant async act scopes (#26350)
Prior to #26347, our internal `act` API (not the public API) behaved differently depending on whether the scope function returned a promise (i.e. was an async function), for historical reasons that no longer apply. Now that this is fixed, I've codemodded all async act scopes that don't contain an await to be sync. No pressing motivation other than it looks nicer and the codemod was easy. Might help avoid confusion for new contributors who see async act scopes with nothing async inside and infer it must be like that for a reason.
1 parent 0373782 commit 62cd5af

File tree

78 files changed

+1277
-1285
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+1277
-1285
lines changed

packages/internal-test-utils/__tests__/ReactInternalTestUtils-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ describe('ReactInternalTestUtils', () => {
152152
}
153153

154154
const root = ReactNoop.createRoot();
155-
await act(async () => {
155+
await act(() => {
156156
root.render(<App />);
157157
});
158158
assertLog(['A', 'B', 'C']);

packages/react-client/src/__tests__/ReactFlight-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ describe('ReactFlight', () => {
475475
return use(promise);
476476
}
477477

478-
await act(async () => {
478+
await act(() => {
479479
startTransition(() => {
480480
ReactNoop.render(
481481
<>
@@ -554,7 +554,7 @@ describe('ReactFlight', () => {
554554
return use(promise);
555555
}
556556

557-
await act(async () => {
557+
await act(() => {
558558
startTransition(() => {
559559
ReactNoop.render(
560560
<NoErrorExpected>

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ describe('ReactHooksInspectionIntegration', () => {
6161
const {onMouseDown: setStateA, onMouseUp: setStateB} =
6262
renderer.root.findByType('div').props;
6363

64-
await act(async () => setStateA('Hi'));
64+
await act(() => setStateA('Hi'));
6565

6666
childFiber = renderer.root.findByType(Foo)._currentFiber();
6767
tree = ReactDebugTools.inspectHooksOfFiber(childFiber);
@@ -83,7 +83,7 @@ describe('ReactHooksInspectionIntegration', () => {
8383
},
8484
]);
8585

86-
await act(async () => setStateB('world!'));
86+
await act(() => setStateB('world!'));
8787

8888
childFiber = renderer.root.findByType(Foo)._currentFiber();
8989
tree = ReactDebugTools.inspectHooksOfFiber(childFiber);
@@ -141,7 +141,7 @@ describe('ReactHooksInspectionIntegration', () => {
141141
);
142142
}
143143
let renderer;
144-
await act(async () => {
144+
await act(() => {
145145
renderer = ReactTestRenderer.create(<Foo prop="prop" />);
146146
});
147147

@@ -203,7 +203,7 @@ describe('ReactHooksInspectionIntegration', () => {
203203
},
204204
]);
205205

206-
await act(async () => {
206+
await act(() => {
207207
updateStates();
208208
});
209209

@@ -301,7 +301,7 @@ describe('ReactHooksInspectionIntegration', () => {
301301
);
302302
}
303303
let renderer;
304-
await act(async () => {
304+
await act(() => {
305305
renderer = ReactTestRenderer.create(<Foo prop="prop" />);
306306
});
307307

@@ -370,7 +370,7 @@ describe('ReactHooksInspectionIntegration', () => {
370370
},
371371
]);
372372

373-
await act(async () => {
373+
await act(() => {
374374
updateStates();
375375
});
376376

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

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

packages/react-dom/src/__tests__/ReactDOMConsoleErrorReporting-test.js

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ describe('ReactDOMConsoleErrorReporting', () => {
7272
}
7373

7474
const root = ReactDOMClient.createRoot(container);
75-
await act(async () => {
75+
await act(() => {
7676
root.render(<Foo />);
7777
});
7878

79-
await act(async () => {
79+
await act(() => {
8080
container.firstChild.dispatchEvent(
8181
new MouseEvent('click', {
8282
bubbles: true,
@@ -146,7 +146,7 @@ describe('ReactDOMConsoleErrorReporting', () => {
146146
// Check next render doesn't throw.
147147
windowOnError.mockReset();
148148
console.error.mockReset();
149-
await act(async () => {
149+
await act(() => {
150150
root.render(<NoError />);
151151
});
152152
expect(container.textContent).toBe('OK');
@@ -229,7 +229,7 @@ describe('ReactDOMConsoleErrorReporting', () => {
229229
// Check next render doesn't throw.
230230
windowOnError.mockReset();
231231
console.error.mockReset();
232-
await act(async () => {
232+
await act(() => {
233233
root.render(<NoError />);
234234
});
235235
expect(container.textContent).toBe('OK');
@@ -247,7 +247,7 @@ describe('ReactDOMConsoleErrorReporting', () => {
247247
}
248248

249249
const root = ReactDOMClient.createRoot(container);
250-
await act(async () => {
250+
await act(() => {
251251
root.render(
252252
<ErrorBoundary>
253253
<Foo />
@@ -315,7 +315,7 @@ describe('ReactDOMConsoleErrorReporting', () => {
315315
// Check next render doesn't throw.
316316
windowOnError.mockReset();
317317
console.error.mockReset();
318-
await act(async () => {
318+
await act(() => {
319319
root.render(<NoError />);
320320
});
321321
expect(container.textContent).toBe('OK');
@@ -384,7 +384,7 @@ describe('ReactDOMConsoleErrorReporting', () => {
384384
// Check next render doesn't throw.
385385
windowOnError.mockReset();
386386
console.error.mockReset();
387-
await act(async () => {
387+
await act(() => {
388388
root.render(<NoError />);
389389
});
390390
expect(container.textContent).toBe('OK');
@@ -405,7 +405,7 @@ describe('ReactDOMConsoleErrorReporting', () => {
405405
}
406406

407407
const root = ReactDOMClient.createRoot(container);
408-
await act(async () => {
408+
await act(() => {
409409
root.render(
410410
<ErrorBoundary>
411411
<Foo />
@@ -456,7 +456,7 @@ describe('ReactDOMConsoleErrorReporting', () => {
456456
// Check next render doesn't throw.
457457
windowOnError.mockReset();
458458
console.error.mockReset();
459-
await act(async () => {
459+
await act(() => {
460460
root.render(<NoError />);
461461
});
462462
expect(container.textContent).toBe('OK');
@@ -525,7 +525,7 @@ describe('ReactDOMConsoleErrorReporting', () => {
525525
// Check next render doesn't throw.
526526
windowOnError.mockReset();
527527
console.error.mockReset();
528-
await act(async () => {
528+
await act(() => {
529529
root.render(<NoError />);
530530
});
531531
expect(container.textContent).toBe('OK');
@@ -546,7 +546,7 @@ describe('ReactDOMConsoleErrorReporting', () => {
546546
}
547547

548548
const root = ReactDOMClient.createRoot(container);
549-
await act(async () => {
549+
await act(() => {
550550
root.render(
551551
<ErrorBoundary>
552552
<Foo />
@@ -597,7 +597,7 @@ describe('ReactDOMConsoleErrorReporting', () => {
597597
// Check next render doesn't throw.
598598
windowOnError.mockReset();
599599
console.error.mockReset();
600-
await act(async () => {
600+
await act(() => {
601601
root.render(<NoError />);
602602
});
603603
expect(container.textContent).toBe('OK');
@@ -623,11 +623,11 @@ describe('ReactDOMConsoleErrorReporting', () => {
623623
);
624624
}
625625

626-
await act(async () => {
626+
await act(() => {
627627
ReactDOM.render(<Foo />, container);
628628
});
629629

630-
await act(async () => {
630+
await act(() => {
631631
container.firstChild.dispatchEvent(
632632
new MouseEvent('click', {
633633
bubbles: true,
@@ -698,7 +698,7 @@ describe('ReactDOMConsoleErrorReporting', () => {
698698
// Check next render doesn't throw.
699699
windowOnError.mockReset();
700700
console.error.mockReset();
701-
await act(async () => {
701+
await act(() => {
702702
ReactDOM.render(<NoError />, container);
703703
});
704704
expect(container.textContent).toBe('OK');
@@ -765,7 +765,7 @@ describe('ReactDOMConsoleErrorReporting', () => {
765765
// Check next render doesn't throw.
766766
windowOnError.mockReset();
767767
console.error.mockReset();
768-
await act(async () => {
768+
await act(() => {
769769
ReactDOM.render(<NoError />, container);
770770
});
771771
expect(container.textContent).toBe('OK');
@@ -784,7 +784,7 @@ describe('ReactDOMConsoleErrorReporting', () => {
784784
throw Error('Boom');
785785
}
786786

787-
await act(async () => {
787+
await act(() => {
788788
ReactDOM.render(
789789
<ErrorBoundary>
790790
<Foo />
@@ -837,7 +837,7 @@ describe('ReactDOMConsoleErrorReporting', () => {
837837
// Check next render doesn't throw.
838838
windowOnError.mockReset();
839839
console.error.mockReset();
840-
await act(async () => {
840+
await act(() => {
841841
ReactDOM.render(<NoError />, container);
842842
});
843843
expect(container.textContent).toBe('OK');
@@ -907,7 +907,7 @@ describe('ReactDOMConsoleErrorReporting', () => {
907907
// Check next render doesn't throw.
908908
windowOnError.mockReset();
909909
console.error.mockReset();
910-
await act(async () => {
910+
await act(() => {
911911
ReactDOM.render(<NoError />, container);
912912
});
913913
expect(container.textContent).toBe('OK');
@@ -929,7 +929,7 @@ describe('ReactDOMConsoleErrorReporting', () => {
929929
return null;
930930
}
931931

932-
await act(async () => {
932+
await act(() => {
933933
ReactDOM.render(
934934
<ErrorBoundary>
935935
<Foo />
@@ -982,7 +982,7 @@ describe('ReactDOMConsoleErrorReporting', () => {
982982
// Check next render doesn't throw.
983983
windowOnError.mockReset();
984984
console.error.mockReset();
985-
await act(async () => {
985+
await act(() => {
986986
ReactDOM.render(<NoError />, container);
987987
});
988988
expect(container.textContent).toBe('OK');
@@ -1053,7 +1053,7 @@ describe('ReactDOMConsoleErrorReporting', () => {
10531053
// Check next render doesn't throw.
10541054
windowOnError.mockReset();
10551055
console.error.mockReset();
1056-
await act(async () => {
1056+
await act(() => {
10571057
ReactDOM.render(<NoError />, container);
10581058
});
10591059
expect(container.textContent).toBe('OK');
@@ -1075,7 +1075,7 @@ describe('ReactDOMConsoleErrorReporting', () => {
10751075
return null;
10761076
}
10771077

1078-
await act(async () => {
1078+
await act(() => {
10791079
ReactDOM.render(
10801080
<ErrorBoundary>
10811081
<Foo />
@@ -1128,7 +1128,7 @@ describe('ReactDOMConsoleErrorReporting', () => {
11281128
// Check next render doesn't throw.
11291129
windowOnError.mockReset();
11301130
console.error.mockReset();
1131-
await act(async () => {
1131+
await act(() => {
11321132
ReactDOM.render(<NoError />, container);
11331133
});
11341134
expect(container.textContent).toBe('OK');

packages/react-dom/src/__tests__/ReactDOMFiberAsync-test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ describe('ReactDOMFiberAsync', () => {
423423
}
424424

425425
const root = ReactDOMClient.createRoot(container);
426-
await act(async () => {
426+
await act(() => {
427427
root.render(<Form />);
428428
});
429429

@@ -474,7 +474,7 @@ describe('ReactDOMFiberAsync', () => {
474474
}
475475

476476
const root = ReactDOMClient.createRoot(container);
477-
await act(async () => {
477+
await act(() => {
478478
root.render(<Form />);
479479
});
480480

@@ -484,7 +484,7 @@ describe('ReactDOMFiberAsync', () => {
484484
// Dispatch a click event on the Disable-button.
485485
const firstEvent = document.createEvent('Event');
486486
firstEvent.initEvent('click', true, true);
487-
await act(async () => {
487+
await act(() => {
488488
disableButton.dispatchEvent(firstEvent);
489489
});
490490

@@ -498,7 +498,7 @@ describe('ReactDOMFiberAsync', () => {
498498
const secondEvent = document.createEvent('Event');
499499
secondEvent.initEvent('click', true, true);
500500
// This should force the pending update to flush which disables the submit button before the event is invoked.
501-
await act(async () => {
501+
await act(() => {
502502
submitButton.dispatchEvent(secondEvent);
503503
});
504504

@@ -533,7 +533,7 @@ describe('ReactDOMFiberAsync', () => {
533533
}
534534

535535
const root = ReactDOMClient.createRoot(container);
536-
await act(async () => {
536+
await act(() => {
537537
root.render(<Form />);
538538
});
539539

@@ -543,7 +543,7 @@ describe('ReactDOMFiberAsync', () => {
543543
// Dispatch a click event on the Enable-button.
544544
const firstEvent = document.createEvent('Event');
545545
firstEvent.initEvent('click', true, true);
546-
await act(async () => {
546+
await act(() => {
547547
enableButton.dispatchEvent(firstEvent);
548548
});
549549

@@ -557,7 +557,7 @@ describe('ReactDOMFiberAsync', () => {
557557
const secondEvent = document.createEvent('Event');
558558
secondEvent.initEvent('click', true, true);
559559
// This should force the pending update to flush which enables the submit button before the event is invoked.
560-
await act(async () => {
560+
await act(() => {
561561
submitButton.dispatchEvent(secondEvent);
562562
});
563563

@@ -643,7 +643,7 @@ describe('ReactDOMFiberAsync', () => {
643643
}
644644

645645
const oldRoot = ReactDOMClient.createRoot(container);
646-
await act(async () => {
646+
await act(() => {
647647
oldRoot.render(<OldApp />);
648648
});
649649

0 commit comments

Comments
 (0)