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
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -4008,4 +4008,76 @@ describe('ReactSuspenseWithNoopRenderer', () => {
);
},
);

// @gate enableLegacyCache
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove this, but probably need the enableRetryLaneExpiration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enableLegacyCache is needed to make the test pass, otherwise text cache in the test setup throws.
enableRetryLaneExpiration has VARIANT flag so it runs with both true and false, I think it's better to have it run both.

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(10000000);
await advanceTimers(10000000);
setText('2');
await waitForPaint(['2']);

await waitFor(['Async', 'A', 'B']);
ReactNoop.expire(10000000);
await advanceTimers(10000000);
setText('3');

// TODO: At this point we want "C" to commit
await waitForPaint(['3']);
await waitFor(['Async', 'A', 'B']);

expect(root).toMatchRenderedOutput(
<>
<span prop="3" />
<span prop="Loading..." />
</>,
);
});
});