Skip to content

Commit

Permalink
[Transition Tracing] Refactor Code to Remove OffscreeInstance TODOs (#…
Browse files Browse the repository at this point in the history
…24855)

Refactored code to pass flow and remove TODOs introduced in #24846
  • Loading branch information
lunaruan authored Jul 6, 2022
1 parent deab126 commit 8e35b50
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 60 deletions.
44 changes: 14 additions & 30 deletions packages/react-reconciler/src/ReactFiberCommitWork.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -2923,56 +2923,40 @@ 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
// caused them
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,
);
}
});
}
Expand Down
44 changes: 14 additions & 30 deletions packages/react-reconciler/src/ReactFiberCommitWork.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -2878,56 +2878,40 @@ 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
// caused them
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,
);
}
});
}
Expand Down

0 comments on commit 8e35b50

Please sign in to comment.