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

Function flushLayoutEffects

packages/react-reconciler/src/ReactFiberWorkLoop.js:3881–3978  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3879}
3880
3881function flushLayoutEffects(): void {
3882 if (pendingEffectsStatus !== PENDING_LAYOUT_PHASE) {
3883 return;
3884 }
3885 pendingEffectsStatus = NO_PENDING_EFFECTS;
3886
3887 if (enableProfilerTimer && enableComponentPerformanceTrack) {
3888 const suspendedViewTransitionReason = pendingSuspendedViewTransitionReason;
3889 if (suspendedViewTransitionReason !== null) {
3890 // We suspended in the middle of the commit for the view transition.
3891 // We'll start a new commit track now.
3892 recordCommitTime();
3893 logSuspendedViewTransitionPhase(
3894 commitEndTime, // The start is the end of the first commit part.
3895 commitStartTime, // The end is the start of the second commit part.
3896 suspendedViewTransitionReason,
3897 animatingTask,
3898 );
3899 }
3900 }
3901
3902 const root = pendingEffectsRoot;
3903 const finishedWork = pendingFinishedWork;
3904 const lanes = pendingEffectsLanes;
3905
3906 if (enableDefaultTransitionIndicator) {
3907 const cleanUpIndicator = root.pendingIndicator;
3908 if (cleanUpIndicator !== null && root.indicatorLanes === NoLanes) {
3909 // We have now committed all Transitions that needed the default indicator
3910 // so we can now run the clean up function. We do this in the layout phase
3911 // so it has the same semantics as if you did it with a useLayoutEffect or
3912 // if it was reset automatically with useOptimistic.
3913 const prevTransition = ReactSharedInternals.T;
3914 ReactSharedInternals.T = null;
3915 const previousPriority = getCurrentUpdatePriority();
3916 setCurrentUpdatePriority(DiscreteEventPriority);
3917 const prevExecutionContext = executionContext;
3918 executionContext |= CommitContext;
3919 root.pendingIndicator = null;
3920 try {
3921 cleanUpIndicator();
3922 } catch (x) {
3923 reportGlobalError(x);
3924 } finally {
3925 // Reset the priority to the previous non-sync value.
3926 executionContext = prevExecutionContext;
3927 setCurrentUpdatePriority(previousPriority);
3928 ReactSharedInternals.T = prevTransition;
3929 }
3930 }
3931 }
3932
3933 const subtreeHasLayoutEffects =
3934 (finishedWork.subtreeFlags & LayoutMask) !== NoFlags;
3935 const rootHasLayoutEffect = (finishedWork.flags & LayoutMask) !== NoFlags;
3936
3937 if (subtreeHasLayoutEffects || rootHasLayoutEffect) {
3938 const prevTransition = ReactSharedInternals.T;

Callers 2

commitRootFunction · 0.85
flushPendingEffectsFunction · 0.85

Calls 9

recordCommitTimeFunction · 0.90
getCurrentUpdatePriorityFunction · 0.90
setCurrentUpdatePriorityFunction · 0.90
markLayoutEffectsStartedFunction · 0.90
commitLayoutEffectsFunction · 0.90
markLayoutEffectsStoppedFunction · 0.90
recordCommitEndTimeFunction · 0.90
logCommitPhaseFunction · 0.90

Tested by

no test coverage detected