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

Suspense layout effects: Failing test case #21853

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @emails react-core
*/

'use strict';

let React;
let ReactDOM;
let TestUtils;

describe('ReactSuspenseEffectsSemanticsDOM', () => {
beforeEach(() => {
jest.resetModules();

React = require('react');
ReactDOM = require('react-dom');
TestUtils = require('react-dom/test-utils');
});

it('should not cause a cycle when combined with a render phase update', () => {
let scheduleSuspendingUpdate;

function App() {
const [value, setValue] = React.useState(true);

scheduleSuspendingUpdate = () => setValue(!value);

return (
<>
<React.Suspense fallback="Loading...">
<ComponentThatCausesBug value={value} />
<ComponentThatSuspendsOnUpdate shouldSuspend={!value} />
</React.Suspense>
</>
);
}

function ComponentThatCausesBug({value}) {
const [mirroredValue, setMirroredValue] = React.useState(value);
if (mirroredValue !== value) {
setMirroredValue(value);
}

// eslint-disable-next-line no-unused-vars
const [_, setRef] = React.useState(null);

return <div ref={setRef} />;
}

const promise = Promise.resolve();

function ComponentThatSuspendsOnUpdate({shouldSuspend}) {
if (shouldSuspend) {
// Fake Suspend
throw promise;
}
return null;
}

TestUtils.act(() => {
const root = ReactDOM.createRoot(document.createElement('div'));
root.render(<App />);
});

TestUtils.act(() => {
scheduleSuspendingUpdate();
});
});
});