Skip to content

Commit

Permalink
Added failing test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn authored and acdlite committed Jul 14, 2021
1 parent 4946ebd commit 88968e2
Showing 1 changed file with 74 additions and 0 deletions.
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 act;

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

React = require('react');
ReactDOM = require('react-dom');
act = require('jest-react').act;
});

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;
}

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

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

0 comments on commit 88968e2

Please sign in to comment.