|
4 | 4 | * This source code is licensed under the MIT license found in the |
5 | 5 | * LICENSE file in the root directory of this source tree. |
6 | 6 | * |
7 | | - * @flow |
| 7 | + * @flow strict |
8 | 8 | */ |
9 | 9 |
|
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 | | - |
25 | 10 | // This version of `act` is only used by our tests. Unlike the public version |
26 | 11 | // of `act`, it's designed to work identically in both production and |
27 | 12 | // development. It may have slightly different behavior from the public |
28 | 13 | // version, too, since our constraints in our test suite are not the same as |
29 | 14 | // those of developers using React — we're testing React itself, as opposed to |
30 | 15 | // 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; |
33 | 24 |
|
34 | 25 | let actingUpdatesScopeDepth = 0; |
35 | 26 |
|
36 | | -export function unstable_concurrentAct(scope: () => Thenable<mixed> | void) { |
| 27 | +export function act(scope: () => Thenable<mixed> | void) { |
37 | 28 | if (Scheduler.unstable_flushAllWithoutAsserting === undefined) { |
38 | 29 | throw Error( |
39 | 30 | 'This version of `act` requires a special mock build of Scheduler.', |
@@ -47,10 +38,6 @@ export function unstable_concurrentAct(scope: () => Thenable<mixed> | void) { |
47 | 38 | } |
48 | 39 |
|
49 | 40 | const previousActingUpdatesScopeDepth = actingUpdatesScopeDepth; |
50 | | - const previousIsSomeRendererActing = IsSomeRendererActing.current; |
51 | | - const previousIsThisRendererActing = IsThisRendererActing.current; |
52 | | - IsSomeRendererActing.current = true; |
53 | | - IsThisRendererActing.current = true; |
54 | 41 | actingUpdatesScopeDepth++; |
55 | 42 | if (__DEV__ && actingUpdatesScopeDepth === 1) { |
56 | 43 | ReactCurrentActQueue.disableActWarning = true; |
@@ -61,8 +48,6 @@ export function unstable_concurrentAct(scope: () => Thenable<mixed> | void) { |
61 | 48 | ReactCurrentActQueue.disableActWarning = false; |
62 | 49 | } |
63 | 50 | actingUpdatesScopeDepth--; |
64 | | - IsSomeRendererActing.current = previousIsSomeRendererActing; |
65 | | - IsThisRendererActing.current = previousIsThisRendererActing; |
66 | 51 |
|
67 | 52 | if (__DEV__) { |
68 | 53 | if (actingUpdatesScopeDepth > previousActingUpdatesScopeDepth) { |
@@ -80,7 +65,7 @@ export function unstable_concurrentAct(scope: () => Thenable<mixed> | void) { |
80 | 65 | // returned and 2) we could use async/await. Since it's only our used in |
81 | 66 | // our test suite, we should be able to. |
82 | 67 | try { |
83 | | - const thenable = batchedUpdates(scope); |
| 68 | + const thenable = scope(); |
84 | 69 | if ( |
85 | 70 | typeof thenable === 'object' && |
86 | 71 | thenable !== null && |
|