Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d7dce57

Browse files
authoredJun 22, 2021
Remove internal act builds from public modules (#21721)
* Move internal version of act to shared module No reason to have three different copies of this anymore. I've left the the renderer-specific `act` entry points because legacy mode tests need to also be wrapped in `batchedUpdates`. Next, I'll update the tests to use `batchedUpdates` manually when needed. * Migrates tests to use internal module directly Instead of the `unstable_concurrentAct` exports. Now we can drop those from the public builds. I put it in the jest-react package since that's where we put our other testing utilities (like `toFlushAndYield`). Not so much so it can be consumed publicly (nobody uses that package except us), but so it works with our build tests. * Remove unused internal fields These were used by the old act implementation. No longer needed.
1 parent 06f7b4f commit d7dce57

File tree

81 files changed

+574
-842
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+574
-842
lines changed
 

‎packages/jest-react/src/JestReact.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import {REACT_ELEMENT_TYPE, REACT_FRAGMENT_TYPE} from 'shared/ReactSymbols';
1010
import invariant from 'shared/invariant';
1111
import isArray from 'shared/isArray';
1212

13+
export {act} from './internalAct';
14+
1315
function captureAssertion(fn) {
1416
// Trick to use a Jest matcher inside another Jest matcher. `fn` contains an
1517
// assertion; if it throws, we capture the error and return it, so the stack

‎packages/react-dom/src/test-utils/ReactTestUtilsInternalAct.js renamed to ‎packages/jest-react/src/internalAct.js

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,27 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @flow
7+
* @flow strict
88
*/
99

10-
import type {Thenable} from 'shared/ReactTypes';
11-
12-
import * as ReactDOM from 'react-dom';
13-
import ReactSharedInternals from 'shared/ReactSharedInternals';
14-
import enqueueTask from 'shared/enqueueTask';
15-
import * as Scheduler from 'scheduler';
16-
17-
const SecretInternals =
18-
ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
19-
const IsThisRendererActing = SecretInternals.IsThisRendererActing;
20-
21-
const batchedUpdates = ReactDOM.unstable_batchedUpdates;
22-
23-
const {IsSomeRendererActing, ReactCurrentActQueue} = ReactSharedInternals;
24-
2510
// This version of `act` is only used by our tests. Unlike the public version
2611
// of `act`, it's designed to work identically in both production and
2712
// development. It may have slightly different behavior from the public
2813
// version, too, since our constraints in our test suite are not the same as
2914
// those of developers using React — we're testing React itself, as opposed to
3015
// building an app with React.
31-
// TODO: Replace the internal "concurrent" implementations of `act` with a
32-
// single shared module.
16+
17+
import type {Thenable} from 'shared/ReactTypes';
18+
19+
import * as Scheduler from 'scheduler/unstable_mock';
20+
21+
import ReactSharedInternals from 'shared/ReactSharedInternals';
22+
import enqueueTask from 'shared/enqueueTask';
23+
const {ReactCurrentActQueue} = ReactSharedInternals;
3324

3425
let actingUpdatesScopeDepth = 0;
3526

36-
export function unstable_concurrentAct(scope: () => Thenable<mixed> | void) {
27+
export function act(scope: () => Thenable<mixed> | void) {
3728
if (Scheduler.unstable_flushAllWithoutAsserting === undefined) {
3829
throw Error(
3930
'This version of `act` requires a special mock build of Scheduler.',
@@ -47,10 +38,6 @@ export function unstable_concurrentAct(scope: () => Thenable<mixed> | void) {
4738
}
4839

4940
const previousActingUpdatesScopeDepth = actingUpdatesScopeDepth;
50-
const previousIsSomeRendererActing = IsSomeRendererActing.current;
51-
const previousIsThisRendererActing = IsThisRendererActing.current;
52-
IsSomeRendererActing.current = true;
53-
IsThisRendererActing.current = true;
5441
actingUpdatesScopeDepth++;
5542
if (__DEV__ && actingUpdatesScopeDepth === 1) {
5643
ReactCurrentActQueue.disableActWarning = true;
@@ -61,8 +48,6 @@ export function unstable_concurrentAct(scope: () => Thenable<mixed> | void) {
6148
ReactCurrentActQueue.disableActWarning = false;
6249
}
6350
actingUpdatesScopeDepth--;
64-
IsSomeRendererActing.current = previousIsSomeRendererActing;
65-
IsThisRendererActing.current = previousIsThisRendererActing;
6651

6752
if (__DEV__) {
6853
if (actingUpdatesScopeDepth > previousActingUpdatesScopeDepth) {
@@ -80,7 +65,7 @@ export function unstable_concurrentAct(scope: () => Thenable<mixed> | void) {
8065
// returned and 2) we could use async/await. Since it's only our used in
8166
// our test suite, we should be able to.
8267
try {
83-
const thenable = batchedUpdates(scope);
68+
const thenable = scope();
8469
if (
8570
typeof thenable === 'object' &&
8671
thenable !== null &&

0 commit comments

Comments
 (0)
Please sign in to comment.