diff --git a/packages/react-reconciler/src/__tests__/ReactSuspenseEffectsSemanticsDOM-test.js b/packages/react-reconciler/src/__tests__/ReactSuspenseEffectsSemanticsDOM-test.js new file mode 100644 index 0000000000000..cca0d3099f153 --- /dev/null +++ b/packages/react-reconciler/src/__tests__/ReactSuspenseEffectsSemanticsDOM-test.js @@ -0,0 +1,78 @@ +/** + * 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 ( + <> + + + + + + ); + } + + function ComponentThatCausesBug({shouldRenderChild}) { + const [mirroredValue, setMirroredValue] = React.useState(shouldRenderChild); + if (mirroredValue !== shouldRenderChild) { + setMirroredValue(shouldRenderChild); + } + + const [_, setRef] = React.useState(null); + + return ( + mirroredValue && ( +
+ ) + ); + } + + + let 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(); + }); + + TestUtils.act(() => { + scheduleSuspendingUpdate(); + }); + }); +}); \ No newline at end of file