Skip to content

Commit 502635b

Browse files
committed
Revert "Support use in act testing API (#25523)"
This reverts commit c635807.
1 parent dd102e8 commit 502635b

5 files changed

Lines changed: 118 additions & 380 deletions

File tree

packages/react-reconciler/src/ReactFiberWakeable.new.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ import type {
1515
RejectedThenable,
1616
} from 'shared/ReactTypes';
1717

18-
import ReactSharedInternals from 'shared/ReactSharedInternals';
19-
const {ReactCurrentActQueue} = ReactSharedInternals;
20-
2118
let suspendedThenable: Thenable<mixed> | null = null;
2219
let adHocSuspendCount: number = 0;
2320

@@ -127,10 +124,6 @@ export function trackUsedThenable<T>(thenable: Thenable<T>, index: number) {
127124
}
128125
usedThenables[index] = thenable;
129126
lastUsedThenable = thenable;
130-
131-
if (__DEV__ && ReactCurrentActQueue.current !== null) {
132-
ReactCurrentActQueue.didUsePromise = true;
133-
}
134127
}
135128

136129
export function getPreviouslyUsedThenableAtIndex<T>(

packages/react-reconciler/src/ReactFiberWakeable.old.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ import type {
1515
RejectedThenable,
1616
} from 'shared/ReactTypes';
1717

18-
import ReactSharedInternals from 'shared/ReactSharedInternals';
19-
const {ReactCurrentActQueue} = ReactSharedInternals;
20-
2118
let suspendedThenable: Thenable<mixed> | null = null;
2219
let adHocSuspendCount: number = 0;
2320

@@ -127,10 +124,6 @@ export function trackUsedThenable<T>(thenable: Thenable<T>, index: number) {
127124
}
128125
usedThenables[index] = thenable;
129126
lastUsedThenable = thenable;
130-
131-
if (__DEV__ && ReactCurrentActQueue.current !== null) {
132-
ReactCurrentActQueue.didUsePromise = true;
133-
}
134127
}
135128

136129
export function getPreviouslyUsedThenableAtIndex<T>(

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

Lines changed: 0 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,15 @@
1212
let React;
1313
let ReactNoop;
1414
let act;
15-
let use;
16-
let Suspense;
1715
let DiscreteEventPriority;
18-
let startTransition;
1916

2017
describe('isomorphic act()', () => {
2118
beforeEach(() => {
2219
React = require('react');
23-
2420
ReactNoop = require('react-noop-renderer');
2521
DiscreteEventPriority = require('react-reconciler/constants')
2622
.DiscreteEventPriority;
2723
act = React.unstable_act;
28-
use = React.experimental_use;
29-
Suspense = React.Suspense;
30-
startTransition = React.startTransition;
3124
});
3225

3326
beforeEach(() => {
@@ -140,154 +133,4 @@ describe('isomorphic act()', () => {
140133
expect(root).toMatchRenderedOutput('C');
141134
});
142135
});
143-
144-
// @gate __DEV__
145-
// @gate enableUseHook
146-
test('unwraps promises by yielding to microtasks (async act scope)', async () => {
147-
const promise = Promise.resolve('Async');
148-
149-
function Fallback() {
150-
throw new Error('Fallback should never be rendered');
151-
}
152-
153-
function App() {
154-
return use(promise);
155-
}
156-
157-
const root = ReactNoop.createRoot();
158-
await act(async () => {
159-
startTransition(() => {
160-
root.render(
161-
<Suspense fallback={<Fallback />}>
162-
<App />
163-
</Suspense>,
164-
);
165-
});
166-
});
167-
expect(root).toMatchRenderedOutput('Async');
168-
});
169-
170-
// @gate __DEV__
171-
// @gate enableUseHook
172-
test('unwraps promises by yielding to microtasks (non-async act scope)', async () => {
173-
const promise = Promise.resolve('Async');
174-
175-
function Fallback() {
176-
throw new Error('Fallback should never be rendered');
177-
}
178-
179-
function App() {
180-
return use(promise);
181-
}
182-
183-
const root = ReactNoop.createRoot();
184-
185-
// Note that the scope function is not an async function
186-
await act(() => {
187-
startTransition(() => {
188-
root.render(
189-
<Suspense fallback={<Fallback />}>
190-
<App />
191-
</Suspense>,
192-
);
193-
});
194-
});
195-
expect(root).toMatchRenderedOutput('Async');
196-
});
197-
198-
// @gate __DEV__
199-
// @gate enableUseHook
200-
test('warns if a promise is used in a non-awaited `act` scope', async () => {
201-
const promise = new Promise(() => {});
202-
203-
function Fallback() {
204-
throw new Error('Fallback should never be rendered');
205-
}
206-
207-
function App() {
208-
return use(promise);
209-
}
210-
211-
spyOnDev(console, 'error');
212-
const root = ReactNoop.createRoot();
213-
act(() => {
214-
startTransition(() => {
215-
root.render(
216-
<Suspense fallback={<Fallback />}>
217-
<App />
218-
</Suspense>,
219-
);
220-
});
221-
});
222-
223-
// `act` warns after a few microtasks, instead of a macrotask, so that it's
224-
// more likely to be attributed to the correct test case.
225-
//
226-
// The exact number of microtasks is an implementation detail; just needs
227-
// to happen when the microtask queue is flushed.
228-
await null;
229-
await null;
230-
await null;
231-
232-
expect(console.error.calls.count()).toBe(1);
233-
expect(console.error.calls.argsFor(0)[0]).toContain(
234-
'Warning: A component suspended inside an `act` scope, but the `act` ' +
235-
'call was not awaited. When testing React components that ' +
236-
'depend on asynchronous data, you must await the result:\n\n' +
237-
'await act(() => ...)',
238-
);
239-
});
240-
241-
// @gate __DEV__
242-
test('does not warn when suspending via legacy `throw` API in non-awaited `act` scope', async () => {
243-
let didResolve = false;
244-
let resolvePromise;
245-
const promise = new Promise(r => {
246-
resolvePromise = () => {
247-
didResolve = true;
248-
r();
249-
};
250-
});
251-
252-
function Fallback() {
253-
return 'Loading...';
254-
}
255-
256-
function App() {
257-
if (!didResolve) {
258-
throw promise;
259-
}
260-
return 'Async';
261-
}
262-
263-
spyOnDev(console, 'error');
264-
const root = ReactNoop.createRoot();
265-
act(() => {
266-
startTransition(() => {
267-
root.render(
268-
<Suspense fallback={<Fallback />}>
269-
<App />
270-
</Suspense>,
271-
);
272-
});
273-
});
274-
expect(root).toMatchRenderedOutput('Loading...');
275-
276-
// `act` warns after a few microtasks, instead of a macrotask, so that it's
277-
// more likely to be attributed to the correct test case.
278-
//
279-
// The exact number of microtasks is an implementation detail; just needs
280-
// to happen when the microtask queue is flushed.
281-
await null;
282-
await null;
283-
await null;
284-
285-
expect(console.error.calls.count()).toBe(0);
286-
287-
// Finish loading the data
288-
await act(async () => {
289-
resolvePromise();
290-
});
291-
expect(root).toMatchRenderedOutput('Async');
292-
});
293136
});

0 commit comments

Comments
 (0)