Skip to content

Commit

Permalink
Regression test: Effects dropped across roots
Browse files Browse the repository at this point in the history
See #17066
  • Loading branch information
acdlite committed Nov 11, 2019
1 parent 2c6ea0b commit 772a01b
Showing 1 changed file with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

'use strict';

const React = require('react');
let React;
let ReactFeatureFlags = require('shared/ReactFeatureFlags');

let ReactDOM;
Expand All @@ -26,6 +26,7 @@ describe('ReactDOMFiberAsync', () => {
beforeEach(() => {
jest.resetModules();
container = document.createElement('div');
React = require('react');
ReactDOM = require('react-dom');
Scheduler = require('scheduler');

Expand Down Expand Up @@ -587,6 +588,39 @@ describe('ReactDOMFiberAsync', () => {
);
});

it('regression test: does not drop passive effects across roots (#17066)', () => {
const {useState, useEffect} = React;

function App({label}) {
const [step, setStep] = useState(0);
useEffect(
() => {
if (step < 3) {
setStep(step + 1);
}
},
[step],
);

// The component should keep re-rendering itself until `step` is 3.
return step === 3 ? 'Finished' : 'Unresolved';
}

const containerA = document.createElement('div');
const containerB = document.createElement('div');
const containerC = document.createElement('div');

ReactDOM.render(<App label="A" />, containerA);
ReactDOM.render(<App label="B" />, containerB);
ReactDOM.render(<App label="C" />, containerC);

Scheduler.unstable_flushAll();

expect(containerA.textContent).toEqual('Finished');
expect(containerB.textContent).toEqual('Finished');
expect(containerC.textContent).toEqual('Finished');
});

describe('createBlockingRoot', () => {
it.experimental('updates flush without yielding in the next event', () => {
const root = ReactDOM.createBlockingRoot(container);
Expand Down

0 comments on commit 772a01b

Please sign in to comment.