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..69d09e0639481 --- /dev/null +++ b/packages/react-reconciler/src/__tests__/ReactSuspenseEffectsSemanticsDOM-test.js @@ -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 ( + <> + + + + + + ); + } + + 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
; + } + + 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(); + }); + + TestUtils.act(() => { + scheduleSuspendingUpdate(); + }); + }); +});