Skip to content

Commit 2f5fe15

Browse files
committed
Codemod act -> await act (4/?)
Similar to the rationale for `waitFor` (see facebook#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 161f6ae commit 2f5fe15

10 files changed

+745
-925
lines changed

packages/react-reconciler/src/__tests__/ReactHooks-test.internal.js

Lines changed: 70 additions & 71 deletions
Large diffs are not rendered by default.

packages/react-reconciler/src/__tests__/ReactHooksWithNoopRenderer-test.js

Lines changed: 101 additions & 102 deletions
Large diffs are not rendered by default.

packages/react-reconciler/src/__tests__/ReactOffscreenStrictMode-test.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ describe('ReactOffscreenStrictMode', () => {
3232
}
3333

3434
// @gate __DEV__ && enableOffscreen
35-
it('should trigger strict effects when offscreen is visible', () => {
36-
act(() => {
35+
it('should trigger strict effects when offscreen is visible', async () => {
36+
await act(async () => {
3737
ReactNoop.render(
3838
<React.StrictMode>
3939
<Offscreen mode="visible">
@@ -56,8 +56,8 @@ describe('ReactOffscreenStrictMode', () => {
5656
});
5757

5858
// @gate __DEV__ && enableOffscreen && useModernStrictMode
59-
it('should not trigger strict effects when offscreen is hidden', () => {
60-
act(() => {
59+
it('should not trigger strict effects when offscreen is hidden', async () => {
60+
await act(async () => {
6161
ReactNoop.render(
6262
<React.StrictMode>
6363
<Offscreen mode="hidden">
@@ -71,7 +71,7 @@ describe('ReactOffscreenStrictMode', () => {
7171

7272
log = [];
7373

74-
act(() => {
74+
await act(async () => {
7575
ReactNoop.render(
7676
<React.StrictMode>
7777
<Offscreen mode="hidden">
@@ -86,7 +86,7 @@ describe('ReactOffscreenStrictMode', () => {
8686

8787
log = [];
8888

89-
act(() => {
89+
await act(async () => {
9090
ReactNoop.render(
9191
<React.StrictMode>
9292
<Offscreen mode="visible">
@@ -109,7 +109,7 @@ describe('ReactOffscreenStrictMode', () => {
109109

110110
log = [];
111111

112-
act(() => {
112+
await act(async () => {
113113
ReactNoop.render(
114114
<React.StrictMode>
115115
<Offscreen mode="hidden">
@@ -127,7 +127,7 @@ describe('ReactOffscreenStrictMode', () => {
127127
]);
128128
});
129129

130-
it('should not cause infinite render loop when StrictMode is used with Suspense and synchronous set states', () => {
130+
it('should not cause infinite render loop when StrictMode is used with Suspense and synchronous set states', async () => {
131131
// This is a regression test, see https://github.com/facebook/react/pull/25179 for more details.
132132
function App() {
133133
const [state, setState] = React.useState(false);
@@ -143,7 +143,7 @@ describe('ReactOffscreenStrictMode', () => {
143143
return state;
144144
}
145145

146-
act(() => {
146+
await act(async () => {
147147
ReactNoop.render(
148148
<React.StrictMode>
149149
<React.Suspense>
@@ -193,7 +193,7 @@ describe('ReactOffscreenStrictMode', () => {
193193
return null;
194194
}
195195

196-
act(() => {
196+
await act(async () => {
197197
ReactNoop.render(
198198
<React.StrictMode>
199199
<Offscreen mode="visible">

0 commit comments

Comments
 (0)