Skip to content

Commit b708aaa

Browse files
committed
Refactor returns
Avoids the temporary mutable variables. I kept losing track of them.
1 parent 9b312d5 commit b708aaa

File tree

1 file changed

+20
-31
lines changed

1 file changed

+20
-31
lines changed

packages/react-reconciler/src/ReactFiberBeginWork.js

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,17 +1511,15 @@ function updateSuspenseComponent(
15111511

15121512
let suspenseContext: SuspenseContext = suspenseStackCursor.current;
15131513

1514-
let nextState = null;
15151514
let nextDidTimeout = false;
1516-
let didSuspend = (workInProgress.effectTag & DidCapture) !== NoEffect;
1515+
const didSuspend = (workInProgress.effectTag & DidCapture) !== NoEffect;
15171516

15181517
if (
15191518
didSuspend ||
15201519
shouldRemainOnFallback(suspenseContext, current, workInProgress)
15211520
) {
15221521
// Something in this boundary's subtree already suspended. Switch to
15231522
// rendering the fallback children.
1524-
nextState = SUSPENDED_MARKER;
15251523
nextDidTimeout = true;
15261524
workInProgress.effectTag &= ~DidCapture;
15271525
} else {
@@ -1586,15 +1584,6 @@ function updateSuspenseComponent(
15861584
// custom reconciliation logic to preserve the state of the primary
15871585
// children. It's essentially a very basic form of re-parenting.
15881586

1589-
// `child` points to the child fiber. In the normal case, this is the first
1590-
// fiber of the primary children set. In the timed-out case, it's a
1591-
// a fragment fiber containing the primary children.
1592-
let child;
1593-
// `next` points to the next fiber React should render. In the normal case,
1594-
// it's the same as `child`: the first fiber of the primary children set.
1595-
// In the timed-out case, it's a fragment fiber containing the *fallback*
1596-
// children -- we skip over the primary children entirely.
1597-
let next;
15981587
if (current === null) {
15991588
if (enableSuspenseServerRenderer) {
16001589
// If we're currently hydrating, try to hydrate this boundary.
@@ -1654,19 +1643,21 @@ function updateSuspenseComponent(
16541643
);
16551644
fallbackChildFragment.return = workInProgress;
16561645
primaryChildFragment.sibling = fallbackChildFragment;
1657-
child = primaryChildFragment;
16581646
// Skip the primary children, and continue working on the
16591647
// fallback children.
1660-
next = fallbackChildFragment;
1648+
workInProgress.memoizedState = SUSPENDED_MARKER;
1649+
workInProgress.child = primaryChildFragment;
1650+
return fallbackChildFragment;
16611651
} else {
16621652
// Mount the primary children without an intermediate fragment fiber.
16631653
const nextPrimaryChildren = nextProps.children;
1664-
child = next = mountChildFibers(
1654+
workInProgress.memoizedState = null;
1655+
return (workInProgress.child = mountChildFibers(
16651656
workInProgress,
16661657
null,
16671658
nextPrimaryChildren,
16681659
renderExpirationTime,
1669-
);
1660+
));
16701661
}
16711662
} else {
16721663
// This is an update. This branch is more complicated because we need to
@@ -1756,11 +1747,10 @@ function updateSuspenseComponent(
17561747
fallbackChildFragment.return = workInProgress;
17571748
primaryChildFragment.sibling = fallbackChildFragment;
17581749
fallbackChildFragment.effectTag |= Placement;
1759-
child = primaryChildFragment;
17601750
primaryChildFragment.childExpirationTime = NoWork;
17611751

1762-
workInProgress.memoizedState = nextState;
1763-
workInProgress.child = child;
1752+
workInProgress.memoizedState = SUSPENDED_MARKER;
1753+
workInProgress.child = primaryChildFragment;
17641754

17651755
// Skip the primary children, and continue working on the
17661756
// fallback children.
@@ -1823,11 +1813,12 @@ function updateSuspenseComponent(
18231813
);
18241814
fallbackChildFragment.return = workInProgress;
18251815
primaryChildFragment.sibling = fallbackChildFragment;
1826-
child = primaryChildFragment;
18271816
primaryChildFragment.childExpirationTime = NoWork;
18281817
// Skip the primary children, and continue working on the
18291818
// fallback children.
1830-
next = fallbackChildFragment;
1819+
workInProgress.memoizedState = SUSPENDED_MARKER;
1820+
workInProgress.child = primaryChildFragment;
1821+
return fallbackChildFragment;
18311822
} else {
18321823
// No longer suspended. Switch back to showing the primary children,
18331824
// and remove the intermediate fragment fiber.
@@ -1847,7 +1838,8 @@ function updateSuspenseComponent(
18471838
// the stateNode?
18481839

18491840
// Continue rendering the children, like we normally do.
1850-
child = next = primaryChild;
1841+
workInProgress.memoizedState = null;
1842+
return (workInProgress.child = primaryChild);
18511843
}
18521844
} else {
18531845
// The current tree has not already timed out. That means the primary
@@ -1915,29 +1907,26 @@ function updateSuspenseComponent(
19151907
fallbackChildFragment.return = workInProgress;
19161908
primaryChildFragment.sibling = fallbackChildFragment;
19171909
fallbackChildFragment.effectTag |= Placement;
1918-
child = primaryChildFragment;
19191910
primaryChildFragment.childExpirationTime = NoWork;
19201911
// Skip the primary children, and continue working on the
19211912
// fallback children.
1922-
next = fallbackChildFragment;
1913+
workInProgress.memoizedState = SUSPENDED_MARKER;
1914+
workInProgress.child = primaryChildFragment;
1915+
return fallbackChildFragment;
19231916
} else {
19241917
// Still haven't timed out. Continue rendering the children, like we
19251918
// normally do.
1919+
workInProgress.memoizedState = null;
19261920
const nextPrimaryChildren = nextProps.children;
1927-
next = child = reconcileChildFibers(
1921+
return (workInProgress.child = reconcileChildFibers(
19281922
workInProgress,
19291923
currentPrimaryChild,
19301924
nextPrimaryChildren,
19311925
renderExpirationTime,
1932-
);
1926+
));
19331927
}
19341928
}
1935-
workInProgress.stateNode = current.stateNode;
19361929
}
1937-
1938-
workInProgress.memoizedState = nextState;
1939-
workInProgress.child = child;
1940-
return next;
19411930
}
19421931

19431932
function retrySuspenseComponentWithoutHydrating(

0 commit comments

Comments
 (0)