Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a regression test for an infinite suspense + Fix #27703

Merged
merged 3 commits into from
Dec 8, 2023
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
4 changes: 3 additions & 1 deletion packages/react-reconciler/src/ReactFiberLane.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,9 @@ export function markStarvedLanesAsExpired(
// We exclude retry lanes because those must always be time sliced, in order
// to unwrap uncached promises.
// TODO: Write a test for this
let lanes = pendingLanes & ~RetryLanes;
let lanes = enableRetryLaneExpiration
? pendingLanes
: pendingLanes & ~RetryLanes;
while (lanes > 0) {
const index = pickArbitraryLaneIndex(lanes);
const lane = 1 << index;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ let Scheduler;
let act;
let waitFor;
let waitForAll;
let waitForMicrotasks;
let assertLog;
let waitForPaint;
let Suspense;
Expand All @@ -29,6 +30,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
waitFor = InternalTestUtils.waitFor;
waitForAll = InternalTestUtils.waitForAll;
waitForPaint = InternalTestUtils.waitForPaint;
waitForMicrotasks = InternalTestUtils.waitForMicrotasks;
assertLog = InternalTestUtils.assertLog;

getCacheForType = React.unstable_getCacheForType;
Expand Down Expand Up @@ -4008,4 +4010,74 @@ describe('ReactSuspenseWithNoopRenderer', () => {
);
},
);

// @gate enableLegacyCache && enableRetryLaneExpiration
it('recurring updates in siblings should not block expensive content in suspense boundary from committing', async () => {
const {useState} = React;

let setText;
function UpdatingText() {
const [text, _setText] = useState('1');
setText = _setText;
return <Text text={text} />;
}

function ExpensiveText({text, ms}) {
Scheduler.log(text);
Scheduler.unstable_advanceTime(ms);
return <span prop={text} />;
}

function App() {
return (
<>
<UpdatingText />
<Suspense fallback={<Text text="Loading..." />}>
<AsyncText text="Async" />
<ExpensiveText text="A" ms={1000} />
<ExpensiveText text="B" ms={3999} />
<ExpensiveText text="C" ms={100000} />
</Suspense>
</>
);
}

const root = ReactNoop.createRoot();
root.render(<App />);
await waitForAll(['1', 'Suspend! [Async]', 'Loading...']);
expect(root).toMatchRenderedOutput(
<>
<span prop="1" />
<span prop="Loading..." />
</>,
);

await resolveText('Async');
expect(root).toMatchRenderedOutput(
<>
<span prop="1" />
<span prop="Loading..." />
</>,
);

await waitFor(['Async', 'A', 'B']);
ReactNoop.expire(100000);
await advanceTimers(100000);
setText('2');
await waitForPaint(['2']);

await waitForMicrotasks();
Scheduler.unstable_flushNumberOfYields(1);
assertLog(['Async', 'A', 'B', 'C']);

expect(root).toMatchRenderedOutput(
<>
<span prop="2" />
<span prop="Async" />
<span prop="A" />
<span prop="B" />
<span prop="C" />
</>,
);
});
});