main
js 70 lines 2.04 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 {FiberRoot} from './ReactInternalTypes';
11 import type {TransitionTypes} from 'react/src/ReactTransitionType';
12
13 import {enableViewTransition} from 'shared/ReactFeatureFlags';
14 import {includesTransitionLane} from './ReactFiberLane';
15
16 export function queueTransitionTypes(
17 root: FiberRoot,
18 transitionTypes: TransitionTypes,
19 ): void {
20 if (enableViewTransition) {
21 // TODO: We should really store transitionTypes per lane in a LaneMap on
22 // the root. Then merge it when we commit. We currently assume that all
23 // Transitions are entangled.
24 if (includesTransitionLane(root.pendingLanes)) {
25 let queued = root.transitionTypes;
26 if (queued === null) {
27 queued = root.transitionTypes = [];
28 }
29 for (let i = 0; i < transitionTypes.length; i++) {
30 const transitionType = transitionTypes[i];
31 if (queued.indexOf(transitionType) === -1) {
32 queued.push(transitionType);
33 }
34 }
35 }
36 }
37 }
38
39 // Store all types while we're entangled with an async Transition.
40 export let entangledTransitionTypes: null | TransitionTypes = null;
41
42 export function entangleAsyncTransitionTypes(
43 transitionTypes: TransitionTypes,
44 ): void {
45 if (enableViewTransition) {
46 let queued = entangledTransitionTypes;
47 if (queued === null) {
48 queued = entangledTransitionTypes = [];
49 }
50 for (let i = 0; i < transitionTypes.length; i++) {
51 const transitionType = transitionTypes[i];
52 if (queued.indexOf(transitionType) === -1) {
53 queued.push(transitionType);
54 }
55 }
56 }
57 }
58
59 export function clearEntangledAsyncTransitionTypes() {
60 // Called when all Async Actions are done.
61 entangledTransitionTypes = null;
62 }
63
64 export function claimQueuedTransitionTypes(
65 root: FiberRoot,
66 ): null | TransitionTypes {
67 const claimed = root.transitionTypes;
68 root.transitionTypes = null;
69 return claimed;
70 }