MCPcopy
hub / github.com/facebook/react / startTransition

Function startTransition

packages/react/src/ReactStartTransition.js:45–117  ·  packages/react/src/ReactStartTransition.js::startTransition
(
  scope: () => void,
  options?: StartTransitionOptions,
)

Source from the content-addressed store, hash-verified

43}
44
45export function startTransition(
46 scope: () => void,
47 options?: StartTransitionOptions,
48): void {
49 const prevTransition = ReactSharedInternals.T;
50 const currentTransition: Transition = ({}: any);
51 if (enableViewTransition) {
52 currentTransition.types =
53 prevTransition !== null
54 ? class="cm">// If we're a nested transition, we should use the same set as the parent
55 class="cm">// since we're conceptually always joined into the same entangled transition.
56 class="cm">// In practice, this only matters if we add transition types in the inner
57 class="cm">// without setting state. In that case, the inner transition can finish
58 class="cm">// without waiting for the outer.
59 prevTransition.types
60 : null;
61 }
62 if (enableGestureTransition) {
63 currentTransition.gesture = null;
64 }
65 if (enableTransitionTracing) {
66 currentTransition.name =
67 options !== undefined && options.name !== undefined ? options.name : null;
68 currentTransition.startTime = -1; class="cm">// TODO: This should read the timestamp.
69 }
70 if (__DEV__) {
71 currentTransition._updatedFibers = new Set();
72 }
73 ReactSharedInternals.T = currentTransition;
74
75 try {
76 const returnValue = scope();
77 const onStartTransitionFinish = ReactSharedInternals.S;
78 if (onStartTransitionFinish !== null) {
79 onStartTransitionFinish(currentTransition, returnValue);
80 }
81 if (
82 typeof returnValue === class="st">'object' &&
83 returnValue !== null &&
84 typeof returnValue.then === class="st">'function'
85 ) {
86 if (__DEV__) {
87 class="cm">// Keep track of the number of async transitions still running so we can warn.
88 ReactSharedInternals.asyncTransitions++;
89 returnValue.then(releaseAsyncTransition, releaseAsyncTransition);
90 }
91 returnValue.then(noop, reportGlobalError);
92 }
93 } catch (error) {
94 reportGlobalError(error);
95 } finally {
96 warnAboutTransitionSubscriptions(prevTransition, currentTransition);
97 if (prevTransition !== null && currentTransition.types !== null) {
98 class="cm">// If we created a new types set in the inner transition, we transfer it to the parent
99 class="cm">// since they should share the same set. They're conceptually entangled.
100 if (__DEV__) {
101 if (
102 prevTransition.types !== null &&

Callers 15

addTransitionTypeFunction · 0.90
checkForUpdateFunction · 0.90
clearCacheBecauseOfErrorFunction · 0.90
fastRefreshScheduledFunction · 0.90
TreeContextControllerFunction · 0.90
toggleTabsFunction · 0.90
handleTabChangeFunction · 0.90
HeaderFunction · 0.90
ConfigEditorFunction · 0.90

Calls 3

thenMethod · 0.65
errorMethod · 0.65

Tested by 7

ComponentFunction · 0.68
AppFunction · 0.68
onSubmitFunction · 0.68
AppFunction · 0.68
AppFunction · 0.68
AppFunction · 0.68
AppFunction · 0.68