main
js 82 lines 2.46 KB
Raw
1 /**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * @flow
8 */
9
10 import type {Dispatcher} from 'react-reconciler/src/ReactInternalTypes';
11 import type {AsyncDispatcher} from 'react-reconciler/src/ReactInternalTypes';
12 import type {Transition} from './ReactStartTransition';
13 import type {GestureProvider, GestureOptions} from 'shared/ReactTypes';
14
15 import {enableGestureTransition} from 'shared/ReactFeatureFlags';
16
17 type onStartTransitionFinish = (Transition, mixed) => void;
18 type onStartGestureTransitionFinish = (
19 Transition,
20 GestureProvider,
21 ?GestureOptions,
22 ) => () => void;
23
24 export type SharedStateClient = {
25 H: null | Dispatcher, // ReactCurrentDispatcher for Hooks
26 A: null | AsyncDispatcher, // ReactCurrentCache for Cache
27 T: null | Transition, // ReactCurrentBatchConfig for Transitions
28 S: null | onStartTransitionFinish,
29 G: null | onStartGestureTransitionFinish,
30
31 // DEV-only
32
33 // ReactCurrentActQueue
34 actQueue: null | Array<RendererTask>,
35
36 // When zero this means we're outside an async startTransition.
37 asyncTransitions: number,
38
39 // Used to reproduce behavior of `batchedUpdates` in legacy mode.
40 isBatchingLegacy: boolean,
41 didScheduleLegacyUpdate: boolean,
42
43 // Tracks whether something called `use` during the current batch of work.
44 // Determines whether we should yield to microtasks to unwrap already resolved
45 // promises without suspending.
46 didUsePromise: boolean,
47
48 // Track first uncaught error within this act
49 thrownErrors: Array<mixed>,
50
51 // ReactDebugCurrentFrame
52 getCurrentStack: null | (() => string),
53
54 // ReactOwnerStackReset
55 recentlyCreatedOwnerStacks: 0,
56 };
57
58 export type RendererTask = boolean => RendererTask | null;
59
60 const ReactSharedInternals: SharedStateClient = {
61 H: null,
62 A: null,
63 T: null,
64 S: null,
65 } as any;
66 if (enableGestureTransition) {
67 ReactSharedInternals.G = null;
68 }
69
70 if (__DEV__) {
71 ReactSharedInternals.actQueue = null;
72 ReactSharedInternals.asyncTransitions = 0;
73 ReactSharedInternals.isBatchingLegacy = false;
74 ReactSharedInternals.didScheduleLegacyUpdate = false;
75 ReactSharedInternals.didUsePromise = false;
76 ReactSharedInternals.thrownErrors = [];
77 // Stack implementation injected by the current renderer.
78 ReactSharedInternals.getCurrentStack = null as null | (() => string);
79 ReactSharedInternals.recentlyCreatedOwnerStacks = 0;
80 }
81
82 export default ReactSharedInternals;