From 8e35b5060875c875f468878f94bc3c0d7d45c52d Mon Sep 17 00:00:00 2001 From: Luna Ruan Date: Wed, 6 Jul 2022 09:38:28 -0400 Subject: [PATCH] [Transition Tracing] Refactor Code to Remove OffscreeInstance TODOs (#24855) Refactored code to pass flow and remove TODOs introduced in #24846 --- .../src/ReactFiberCommitWork.new.js | 44 ++++++------------- .../src/ReactFiberCommitWork.old.js | 44 ++++++------------- 2 files changed, 28 insertions(+), 60 deletions(-) diff --git a/packages/react-reconciler/src/ReactFiberCommitWork.new.js b/packages/react-reconciler/src/ReactFiberCommitWork.new.js index 3d19e98ccb048..e5cfebea5f88c 100644 --- a/packages/react-reconciler/src/ReactFiberCommitWork.new.js +++ b/packages/react-reconciler/src/ReactFiberCommitWork.new.js @@ -2923,34 +2923,21 @@ function commitPassiveMountOnFiber( if (queue !== null) { if (isFallback) { const transitions = queue.transitions; - let prevTransitions = instance.transitions; - if (instance.pendingMarkers === null) { - instance.pendingMarkers = new Set(); - } - if (transitions !== null && prevTransitions === null) { - instance.transitions = prevTransitions = new Set(); - } - if (transitions !== null) { transitions.forEach(transition => { // Add all the transitions saved in the update queue during // the render phase (ie the transitions associated with this boundary) // into the transitions set. - if (prevTransitions === null) { - // TODO: What if prevTransitions is null? - } else { - prevTransitions.add(transition); + if (instance.transitions === null) { + instance.transitions = new Set(); } + instance.transitions.add(transition); }); } const markerInstances = queue.markerInstances; if (markerInstances !== null) { markerInstances.forEach(markerInstance => { - if (markerInstance.pendingSuspenseBoundaries === null) { - markerInstance.pendingSuspenseBoundaries = new Map(); - } - const markerTransitions = markerInstance.transitions; // There should only be a few tracing marker transitions because // they should be only associated with the transition that @@ -2958,21 +2945,18 @@ function commitPassiveMountOnFiber( if (markerTransitions !== null) { markerTransitions.forEach(transition => { if (instance.transitions === null) { - // TODO: What if instance.transitions is null? - } else { - if (instance.transitions.has(transition)) { - if ( - instance.pendingMarkers === null || - markerInstance.pendingSuspenseBoundaries === null - ) { - // TODO: What if instance.pendingMarkers is null? - // TODO: What if markerInstance.pendingSuspenseBoundaries is null? - } else { - instance.pendingMarkers.add( - markerInstance.pendingSuspenseBoundaries, - ); - } + instance.transitions = new Set(); + } else if (instance.transitions.has(transition)) { + if (markerInstance.pendingSuspenseBoundaries === null) { + markerInstance.pendingSuspenseBoundaries = new Map(); + } + if (instance.pendingMarkers === null) { + instance.pendingMarkers = new Set(); } + + instance.pendingMarkers.add( + markerInstance.pendingSuspenseBoundaries, + ); } }); } diff --git a/packages/react-reconciler/src/ReactFiberCommitWork.old.js b/packages/react-reconciler/src/ReactFiberCommitWork.old.js index 54030004af755..eae4bc52e3585 100644 --- a/packages/react-reconciler/src/ReactFiberCommitWork.old.js +++ b/packages/react-reconciler/src/ReactFiberCommitWork.old.js @@ -2878,34 +2878,21 @@ function commitPassiveMountOnFiber( if (queue !== null) { if (isFallback) { const transitions = queue.transitions; - let prevTransitions = instance.transitions; - if (instance.pendingMarkers === null) { - instance.pendingMarkers = new Set(); - } - if (transitions !== null && prevTransitions === null) { - instance.transitions = prevTransitions = new Set(); - } - if (transitions !== null) { transitions.forEach(transition => { // Add all the transitions saved in the update queue during // the render phase (ie the transitions associated with this boundary) // into the transitions set. - if (prevTransitions === null) { - // TODO: What if prevTransitions is null? - } else { - prevTransitions.add(transition); + if (instance.transitions === null) { + instance.transitions = new Set(); } + instance.transitions.add(transition); }); } const markerInstances = queue.markerInstances; if (markerInstances !== null) { markerInstances.forEach(markerInstance => { - if (markerInstance.pendingSuspenseBoundaries === null) { - markerInstance.pendingSuspenseBoundaries = new Map(); - } - const markerTransitions = markerInstance.transitions; // There should only be a few tracing marker transitions because // they should be only associated with the transition that @@ -2913,21 +2900,18 @@ function commitPassiveMountOnFiber( if (markerTransitions !== null) { markerTransitions.forEach(transition => { if (instance.transitions === null) { - // TODO: What if instance.transitions is null? - } else { - if (instance.transitions.has(transition)) { - if ( - instance.pendingMarkers === null || - markerInstance.pendingSuspenseBoundaries === null - ) { - // TODO: What if instance.pendingMarkers is null? - // TODO: What if markerInstance.pendingSuspenseBoundaries is null? - } else { - instance.pendingMarkers.add( - markerInstance.pendingSuspenseBoundaries, - ); - } + instance.transitions = new Set(); + } else if (instance.transitions.has(transition)) { + if (markerInstance.pendingSuspenseBoundaries === null) { + markerInstance.pendingSuspenseBoundaries = new Map(); + } + if (instance.pendingMarkers === null) { + instance.pendingMarkers = new Set(); } + + instance.pendingMarkers.add( + markerInstance.pendingSuspenseBoundaries, + ); } }); }