Skip to content

Commit 58605f7

Browse files
authored
Codemod act -> await act (2/?) (#26335)
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.
1 parent 703c675 commit 58605f7

11 files changed

+168
-168
lines changed

packages/react-dom/src/__tests__/ReactDOMServerSuspense-test.internal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ describe('ReactDOMServerSuspense', () => {
161161
expect(divB.tagName).toBe('DIV');
162162
expect(divB.textContent).toBe('B');
163163

164-
act(() => {
164+
await act(async () => {
165165
ReactDOMClient.hydrateRoot(parent, example);
166166
});
167167

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,23 +153,15 @@ describe('ReactDOMSuspensePlaceholder', () => {
153153
);
154154
}
155155

156-
act(() => {
156+
await act(async () => {
157157
ReactDOM.render(<App />, container);
158158
});
159159
expect(container.innerHTML).toEqual(
160160
'<span style="display: none;">Sibling</span><span style=' +
161161
'"display: none;"></span>Loading...',
162162
);
163163

164-
act(() => setIsVisible(true));
165-
expect(container.innerHTML).toEqual(
166-
'<span style="display: none;">Sibling</span><span style=' +
167-
'"display: none;"></span>Loading...',
168-
);
169-
170-
await advanceTimers(500);
171-
172-
Scheduler.unstable_flushAll();
164+
await act(async () => setIsVisible(true));
173165

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy