Skip to content

Commit

Permalink
Codemod act -> await act (2/?)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
acdlite committed Mar 7, 2023
1 parent 703c675 commit b0727e3
Show file tree
Hide file tree
Showing 11 changed files with 172 additions and 169 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ describe('ReactDOMServerSuspense', () => {
expect(divB.tagName).toBe('DIV');
expect(divB.textContent).toBe('B');

act(() => {
await act(async () => {
ReactDOMClient.hydrateRoot(parent, example);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,23 +153,15 @@ describe('ReactDOMSuspensePlaceholder', () => {
);
}

act(() => {
await act(async () => {
ReactDOM.render(<App />, container);
});
expect(container.innerHTML).toEqual(
'<span style="display: none;">Sibling</span><span style=' +
'"display: none;"></span>Loading...',
);

act(() => setIsVisible(true));
expect(container.innerHTML).toEqual(
'<span style="display: none;">Sibling</span><span style=' +
'"display: none;"></span>Loading...',
);

await advanceTimers(500);

Scheduler.unstable_flushAll();
await act(async () => setIsVisible(true));

expect(container.innerHTML).toEqual(
'<span style="display: inline;">Sibling</span><span style="">Async</span>',
Expand Down
Loading

0 comments on commit b0727e3

Please sign in to comment.