Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 26 additions & 21 deletions packages/react-reconciler/src/ReactFiberBeginWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -2782,29 +2782,26 @@ function beginWork(
const didSuspendBefore =
(current.effectTag & DidCapture) !== NoEffect;

const childExpirationTime = workInProgress.childExpirationTime;
if (childExpirationTime < renderExpirationTime) {
const hasChildWork =
workInProgress.childExpirationTime >= renderExpirationTime;

if (didSuspendBefore) {
if (hasChildWork) {
// If something was in fallback state last time, and we have all the
// same children then we're still in progressive loading state.
// Something might get unblocked by state updates or retries in the
// tree which will affect the tail. So we need to use the normal
// path to compute the correct tail.
return updateSuspenseListComponent(
current,
workInProgress,
renderExpirationTime,
);
}
// If none of the children had any work, that means that none of
// them got retried so they'll still be blocked in the same way
// as before. We can fast bail out.
pushSuspenseContext(workInProgress, suspenseStackCursor.current);
if (didSuspendBefore) {
workInProgress.effectTag |= DidCapture;
}
return null;
}

if (didSuspendBefore) {
// If something was in fallback state last time, and we have all the
// same children then we're still in progressive loading state.
// Something might get unblocked by state updates or retries in the
// tree which will affect the tail. So we need to use the normal
// path to compute the correct tail.
return updateSuspenseListComponent(
current,
workInProgress,
renderExpirationTime,
);
workInProgress.effectTag |= DidCapture;
}

// If nothing suspended before and we're rendering the same children,
Expand All @@ -2818,7 +2815,15 @@ function beginWork(
renderState.tail = null;
}
pushSuspenseContext(workInProgress, suspenseStackCursor.current);
break;

if (hasChildWork) {
break;
} else {
// If none of the children had any work, that means that none of
// them got retried so they'll still be blocked in the same way
// as before. We can fast bail out.
return null;
}
}
}
return bailoutOnAlreadyFinishedWork(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1826,4 +1826,50 @@ describe('ReactSuspenseList', () => {
</Fragment>,
);
});

it('can do unrelated adjacent updates', async () => {
let updateAdjacent;
function Adjacent() {
let [text, setText] = React.useState('-');
updateAdjacent = setText;
return <Text text={text} />;
}

function Foo() {
return (
<div>
<SuspenseList revealOrder="forwards">
<Text text="A" />
<Text text="B" />
</SuspenseList>
<Adjacent />
</div>
);
}

ReactNoop.render(<Foo />);

expect(Scheduler).toFlushAndYield(['A', 'B', '-']);

expect(ReactNoop).toMatchRenderedOutput(
<div>
<span>A</span>
<span>B</span>
<span>-</span>
</div>,
);

// Update the row adjacent to the list
ReactNoop.act(() => updateAdjacent('C'));

expect(Scheduler).toHaveYielded(['C']);

expect(ReactNoop).toMatchRenderedOutput(
<div>
<span>A</span>
<span>B</span>
<span>C</span>
</div>,
);
});
});