From fcd720d3631a23a9e273db60bf2d35ff5f7dc406 Mon Sep 17 00:00:00 2001 From: Luna Ruan Date: Wed, 15 Jun 2022 11:51:51 -0700 Subject: [PATCH] [Transition Tracing] Push Transition When Offscreen Becomes Visible (#24718) This PR pushes all of a suspense boundary's transitions onto the transition stack when it goes from hidden to visible so we can pass it to any child suspense boundaries or tracing markers. --- .../react-reconciler/src/ReactFiberBeginWork.new.js | 12 +++++++++++- .../react-reconciler/src/ReactFiberBeginWork.old.js | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/packages/react-reconciler/src/ReactFiberBeginWork.new.js b/packages/react-reconciler/src/ReactFiberBeginWork.new.js index 0688ae8a04f6e..c8c1f3cbb05a9 100644 --- a/packages/react-reconciler/src/ReactFiberBeginWork.new.js +++ b/packages/react-reconciler/src/ReactFiberBeginWork.new.js @@ -779,7 +779,17 @@ function updateOffscreenComponent( prevCachePool = prevState.cachePool; } - pushTransition(workInProgress, prevCachePool, null); + let transitions = null; + if ( + workInProgress.memoizedState !== null && + workInProgress.memoizedState.transitions !== null + ) { + // We have now gone from hidden to visible, so any transitions should + // be added to the stack to get added to any Offscreen/suspense children + transitions = workInProgress.memoizedState.transitions; + } + + pushTransition(workInProgress, prevCachePool, transitions); // Since we're not hidden anymore, reset the state workInProgress.memoizedState = null; diff --git a/packages/react-reconciler/src/ReactFiberBeginWork.old.js b/packages/react-reconciler/src/ReactFiberBeginWork.old.js index 74595fda43425..8f98c76b3b1aa 100644 --- a/packages/react-reconciler/src/ReactFiberBeginWork.old.js +++ b/packages/react-reconciler/src/ReactFiberBeginWork.old.js @@ -779,7 +779,17 @@ function updateOffscreenComponent( prevCachePool = prevState.cachePool; } - pushTransition(workInProgress, prevCachePool, null); + let transitions = null; + if ( + workInProgress.memoizedState !== null && + workInProgress.memoizedState.transitions !== null + ) { + // We have now gone from hidden to visible, so any transitions should + // be added to the stack to get added to any Offscreen/suspense children + transitions = workInProgress.memoizedState.transitions; + } + + pushTransition(workInProgress, prevCachePool, transitions); // Since we're not hidden anymore, reset the state workInProgress.memoizedState = null;