Skip to content

Commit

Permalink
Codemod act -> await act (4/?)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
acdlite committed Mar 8, 2023
1 parent 161f6ae commit 1a0c53d
Show file tree
Hide file tree
Showing 10 changed files with 744 additions and 929 deletions.
141 changes: 70 additions & 71 deletions packages/react-reconciler/src/__tests__/ReactHooks-test.internal.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ describe('ReactOffscreenStrictMode', () => {
}

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

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

log = [];

act(() => {
await act(async () => {
ReactNoop.render(
<React.StrictMode>
<Offscreen mode="hidden">
Expand All @@ -86,7 +86,7 @@ describe('ReactOffscreenStrictMode', () => {

log = [];

act(() => {
await act(async () => {
ReactNoop.render(
<React.StrictMode>
<Offscreen mode="visible">
Expand All @@ -109,7 +109,7 @@ describe('ReactOffscreenStrictMode', () => {

log = [];

act(() => {
await act(async () => {
ReactNoop.render(
<React.StrictMode>
<Offscreen mode="hidden">
Expand All @@ -127,7 +127,7 @@ describe('ReactOffscreenStrictMode', () => {
]);
});

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

act(() => {
await act(async () => {
ReactNoop.render(
<React.StrictMode>
<React.Suspense>
Expand Down Expand Up @@ -193,7 +193,7 @@ describe('ReactOffscreenStrictMode', () => {
return null;
}

act(() => {
await act(async () => {
ReactNoop.render(
<React.StrictMode>
<Offscreen mode="visible">
Expand Down
Loading

0 comments on commit 1a0c53d

Please sign in to comment.