Skip to content

Commit

Permalink
isShowingAnyFallbacks -> findFirstFallback
Browse files Browse the repository at this point in the history
This lets us reuse the found fallback so we can transfer the update queue
from it.
  • Loading branch information
sebmarkbage committed Jul 12, 2019
1 parent 6278269 commit 8039935
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
6 changes: 3 additions & 3 deletions packages/react-reconciler/src/ReactFiberBeginWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ import {
addSubtreeSuspenseContext,
setShallowSuspenseContext,
} from './ReactFiberSuspenseContext';
import {isShowingAnyFallbacks} from './ReactFiberSuspenseComponent';
import {findFirstFallback} from './ReactFiberSuspenseComponent';
import {
pushProvider,
propagateContextChange,
Expand Down Expand Up @@ -2000,7 +2000,7 @@ function findLastContentRow(firstChild: null | Fiber): null | Fiber {
while (row !== null) {
let currentRow = row.alternate;
// New rows can't be content rows.
if (currentRow !== null && !isShowingAnyFallbacks(currentRow)) {
if (currentRow !== null && findFirstFallback(currentRow) === null) {
lastContentRow = row;
}
row = row.sibling;
Expand Down Expand Up @@ -2281,7 +2281,7 @@ function updateSuspenseListComponent(
while (row !== null) {
let currentRow = row.alternate;
// New rows can't be content rows.
if (currentRow !== null && !isShowingAnyFallbacks(currentRow)) {
if (currentRow !== null && findFirstFallback(currentRow) === null) {
// This is the beginning of the main content.
workInProgress.child = row;
break;
Expand Down
13 changes: 8 additions & 5 deletions packages/react-reconciler/src/ReactFiberCompleteWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ import {
ForceSuspenseFallback,
setDefaultShallowSuspenseContext,
} from './ReactFiberSuspenseContext';
import {isShowingAnyFallbacks} from './ReactFiberSuspenseComponent';
import {findFirstFallback} from './ReactFiberSuspenseComponent';
import {
isContextProvider as isLegacyContextProvider,
popContext as popLegacyContext,
Expand Down Expand Up @@ -1061,7 +1061,8 @@ function completeWork(
} else {
// Append the rendered row to the child list.
if (!didSuspendAlready) {
if (isShowingAnyFallbacks(renderedTail)) {
let fallback = findFirstFallback(renderedTail);
if (fallback !== null) {
workInProgress.effectTag |= DidCapture;
didSuspendAlready = true;
cutOffTailIfNeeded(renderState, true);
Expand All @@ -1072,9 +1073,11 @@ function completeWork(
) {
// We need to delete the row we just rendered.
// Ensure we transfer the update queue to the parent.
// TODO: This just reuses the code from the other path but could
// be optimized better.
hasSuspendedChildrenAndNewContent(workInProgress, renderedTail);
let fallbackThennables = fallback.updateQueue;
if (fallbackThennables !== null) {
workInProgress.updateQueue = fallbackThennables;
workInProgress.effectTag |= Update;
}
// Reset the effect list to what it w as before we rendered this
// child. The nested children have already appended themselves.
let lastEffect = (workInProgress.lastEffect =
Expand Down
10 changes: 5 additions & 5 deletions packages/react-reconciler/src/ReactFiberSuspenseComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,30 +61,30 @@ export function shouldCaptureSuspense(
return true;
}

export function isShowingAnyFallbacks(row: Fiber): boolean {
export function findFirstFallback(row: Fiber): null | Fiber {
let node = row;
while (node !== null) {
if (node.tag === SuspenseComponent) {
const state: SuspenseState | null = node.memoizedState;
if (state !== null) {
return true;
return node;
}
} else if (node.child !== null) {
node.child.return = node;
node = node.child;
continue;
}
if (node === row) {
return false;
return null;
}
while (node.sibling === null) {
if (node.return === null || node.return === row) {
return false;
return null;
}
node = node.return;
}
node.sibling.return = node.return;
node = node.sibling;
}
return false;
return null;
}

0 comments on commit 8039935

Please sign in to comment.