| 43 | } |
| 44 | |
| 45 | export 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 && |