Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Codemod redundant async act scopes #26350

Merged
merged 1 commit into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ describe('ReactInternalTestUtils', () => {
}

const root = ReactNoop.createRoot();
await act(async () => {
await act(() => {
root.render(<App />);
});
assertLog(['A', 'B', 'C']);
Expand Down
4 changes: 2 additions & 2 deletions packages/react-client/src/__tests__/ReactFlight-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ describe('ReactFlight', () => {
return use(promise);
}

await act(async () => {
await act(() => {
startTransition(() => {
ReactNoop.render(
<>
Expand Down Expand Up @@ -554,7 +554,7 @@ describe('ReactFlight', () => {
return use(promise);
}

await act(async () => {
await act(() => {
startTransition(() => {
ReactNoop.render(
<NoErrorExpected>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('ReactHooksInspectionIntegration', () => {
const {onMouseDown: setStateA, onMouseUp: setStateB} =
renderer.root.findByType('div').props;

await act(async () => setStateA('Hi'));
await act(() => setStateA('Hi'));

childFiber = renderer.root.findByType(Foo)._currentFiber();
tree = ReactDebugTools.inspectHooksOfFiber(childFiber);
Expand All @@ -83,7 +83,7 @@ describe('ReactHooksInspectionIntegration', () => {
},
]);

await act(async () => setStateB('world!'));
await act(() => setStateB('world!'));

childFiber = renderer.root.findByType(Foo)._currentFiber();
tree = ReactDebugTools.inspectHooksOfFiber(childFiber);
Expand Down Expand Up @@ -141,7 +141,7 @@ describe('ReactHooksInspectionIntegration', () => {
);
}
let renderer;
await act(async () => {
await act(() => {
renderer = ReactTestRenderer.create(<Foo prop="prop" />);
});

Expand Down Expand Up @@ -203,7 +203,7 @@ describe('ReactHooksInspectionIntegration', () => {
},
]);

await act(async () => {
await act(() => {
updateStates();
});

Expand Down Expand Up @@ -301,7 +301,7 @@ describe('ReactHooksInspectionIntegration', () => {
);
}
let renderer;
await act(async () => {
await act(() => {
renderer = ReactTestRenderer.create(<Foo prop="prop" />);
});

Expand Down Expand Up @@ -370,7 +370,7 @@ describe('ReactHooksInspectionIntegration', () => {
},
]);

await act(async () => {
await act(() => {
updateStates();
});

Expand Down Expand Up @@ -984,7 +984,7 @@ describe('ReactHooksInspectionIntegration', () => {
children: ['count: ', '1'],
});

await act(async () => incrementCount());
await act(() => incrementCount());
expect(renderer.toJSON()).toEqual({
type: 'div',
props: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ describe('ReactDOMConsoleErrorReporting', () => {
}

const root = ReactDOMClient.createRoot(container);
await act(async () => {
await act(() => {
root.render(<Foo />);
});

await act(async () => {
await act(() => {
container.firstChild.dispatchEvent(
new MouseEvent('click', {
bubbles: true,
Expand Down Expand Up @@ -146,7 +146,7 @@ describe('ReactDOMConsoleErrorReporting', () => {
// Check next render doesn't throw.
windowOnError.mockReset();
console.error.mockReset();
await act(async () => {
await act(() => {
root.render(<NoError />);
});
expect(container.textContent).toBe('OK');
Expand Down Expand Up @@ -229,7 +229,7 @@ describe('ReactDOMConsoleErrorReporting', () => {
// Check next render doesn't throw.
windowOnError.mockReset();
console.error.mockReset();
await act(async () => {
await act(() => {
root.render(<NoError />);
});
expect(container.textContent).toBe('OK');
Expand All @@ -247,7 +247,7 @@ describe('ReactDOMConsoleErrorReporting', () => {
}

const root = ReactDOMClient.createRoot(container);
await act(async () => {
await act(() => {
root.render(
<ErrorBoundary>
<Foo />
Expand Down Expand Up @@ -315,7 +315,7 @@ describe('ReactDOMConsoleErrorReporting', () => {
// Check next render doesn't throw.
windowOnError.mockReset();
console.error.mockReset();
await act(async () => {
await act(() => {
root.render(<NoError />);
});
expect(container.textContent).toBe('OK');
Expand Down Expand Up @@ -384,7 +384,7 @@ describe('ReactDOMConsoleErrorReporting', () => {
// Check next render doesn't throw.
windowOnError.mockReset();
console.error.mockReset();
await act(async () => {
await act(() => {
root.render(<NoError />);
});
expect(container.textContent).toBe('OK');
Expand All @@ -405,7 +405,7 @@ describe('ReactDOMConsoleErrorReporting', () => {
}

const root = ReactDOMClient.createRoot(container);
await act(async () => {
await act(() => {
root.render(
<ErrorBoundary>
<Foo />
Expand Down Expand Up @@ -456,7 +456,7 @@ describe('ReactDOMConsoleErrorReporting', () => {
// Check next render doesn't throw.
windowOnError.mockReset();
console.error.mockReset();
await act(async () => {
await act(() => {
root.render(<NoError />);
});
expect(container.textContent).toBe('OK');
Expand Down Expand Up @@ -525,7 +525,7 @@ describe('ReactDOMConsoleErrorReporting', () => {
// Check next render doesn't throw.
windowOnError.mockReset();
console.error.mockReset();
await act(async () => {
await act(() => {
root.render(<NoError />);
});
expect(container.textContent).toBe('OK');
Expand All @@ -546,7 +546,7 @@ describe('ReactDOMConsoleErrorReporting', () => {
}

const root = ReactDOMClient.createRoot(container);
await act(async () => {
await act(() => {
root.render(
<ErrorBoundary>
<Foo />
Expand Down Expand Up @@ -597,7 +597,7 @@ describe('ReactDOMConsoleErrorReporting', () => {
// Check next render doesn't throw.
windowOnError.mockReset();
console.error.mockReset();
await act(async () => {
await act(() => {
root.render(<NoError />);
});
expect(container.textContent).toBe('OK');
Expand All @@ -623,11 +623,11 @@ describe('ReactDOMConsoleErrorReporting', () => {
);
}

await act(async () => {
await act(() => {
ReactDOM.render(<Foo />, container);
});

await act(async () => {
await act(() => {
container.firstChild.dispatchEvent(
new MouseEvent('click', {
bubbles: true,
Expand Down Expand Up @@ -698,7 +698,7 @@ describe('ReactDOMConsoleErrorReporting', () => {
// Check next render doesn't throw.
windowOnError.mockReset();
console.error.mockReset();
await act(async () => {
await act(() => {
ReactDOM.render(<NoError />, container);
});
expect(container.textContent).toBe('OK');
Expand Down Expand Up @@ -765,7 +765,7 @@ describe('ReactDOMConsoleErrorReporting', () => {
// Check next render doesn't throw.
windowOnError.mockReset();
console.error.mockReset();
await act(async () => {
await act(() => {
ReactDOM.render(<NoError />, container);
});
expect(container.textContent).toBe('OK');
Expand All @@ -784,7 +784,7 @@ describe('ReactDOMConsoleErrorReporting', () => {
throw Error('Boom');
}

await act(async () => {
await act(() => {
ReactDOM.render(
<ErrorBoundary>
<Foo />
Expand Down Expand Up @@ -837,7 +837,7 @@ describe('ReactDOMConsoleErrorReporting', () => {
// Check next render doesn't throw.
windowOnError.mockReset();
console.error.mockReset();
await act(async () => {
await act(() => {
ReactDOM.render(<NoError />, container);
});
expect(container.textContent).toBe('OK');
Expand Down Expand Up @@ -907,7 +907,7 @@ describe('ReactDOMConsoleErrorReporting', () => {
// Check next render doesn't throw.
windowOnError.mockReset();
console.error.mockReset();
await act(async () => {
await act(() => {
ReactDOM.render(<NoError />, container);
});
expect(container.textContent).toBe('OK');
Expand All @@ -929,7 +929,7 @@ describe('ReactDOMConsoleErrorReporting', () => {
return null;
}

await act(async () => {
await act(() => {
ReactDOM.render(
<ErrorBoundary>
<Foo />
Expand Down Expand Up @@ -982,7 +982,7 @@ describe('ReactDOMConsoleErrorReporting', () => {
// Check next render doesn't throw.
windowOnError.mockReset();
console.error.mockReset();
await act(async () => {
await act(() => {
ReactDOM.render(<NoError />, container);
});
expect(container.textContent).toBe('OK');
Expand Down Expand Up @@ -1053,7 +1053,7 @@ describe('ReactDOMConsoleErrorReporting', () => {
// Check next render doesn't throw.
windowOnError.mockReset();
console.error.mockReset();
await act(async () => {
await act(() => {
ReactDOM.render(<NoError />, container);
});
expect(container.textContent).toBe('OK');
Expand All @@ -1075,7 +1075,7 @@ describe('ReactDOMConsoleErrorReporting', () => {
return null;
}

await act(async () => {
await act(() => {
ReactDOM.render(
<ErrorBoundary>
<Foo />
Expand Down Expand Up @@ -1128,7 +1128,7 @@ describe('ReactDOMConsoleErrorReporting', () => {
// Check next render doesn't throw.
windowOnError.mockReset();
console.error.mockReset();
await act(async () => {
await act(() => {
ReactDOM.render(<NoError />, container);
});
expect(container.textContent).toBe('OK');
Expand Down
16 changes: 8 additions & 8 deletions packages/react-dom/src/__tests__/ReactDOMFiberAsync-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ describe('ReactDOMFiberAsync', () => {
}

const root = ReactDOMClient.createRoot(container);
await act(async () => {
await act(() => {
root.render(<Form />);
});

Expand Down Expand Up @@ -474,7 +474,7 @@ describe('ReactDOMFiberAsync', () => {
}

const root = ReactDOMClient.createRoot(container);
await act(async () => {
await act(() => {
root.render(<Form />);
});

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

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

Expand Down Expand Up @@ -533,7 +533,7 @@ describe('ReactDOMFiberAsync', () => {
}

const root = ReactDOMClient.createRoot(container);
await act(async () => {
await act(() => {
root.render(<Form />);
});

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

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

Expand Down Expand Up @@ -643,7 +643,7 @@ describe('ReactDOMFiberAsync', () => {
}

const oldRoot = ReactDOMClient.createRoot(container);
await act(async () => {
await act(() => {
oldRoot.render(<OldApp />);
});

Expand Down
Loading