Skip to content

Commit 3fac6a7

Browse files
committed
Failing test: Class callback fired multiple times
Happens during a rebase (low priority update followed by high priority update). The high priority callback gets fired twice.
1 parent b770f75 commit 3fac6a7

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
let React;
2+
let ReactNoop;
3+
let Scheduler;
4+
5+
describe('ReactClassSetStateCallback', () => {
6+
beforeEach(() => {
7+
jest.resetModules();
8+
9+
React = require('react');
10+
ReactNoop = require('react-noop-renderer');
11+
Scheduler = require('scheduler');
12+
});
13+
14+
function Text({text}) {
15+
Scheduler.unstable_yieldValue(text);
16+
return text;
17+
}
18+
19+
test('regression: setState callback (2nd arg) should only fire once, even after a rebase', async () => {
20+
let app;
21+
class App extends React.Component {
22+
state = {step: 0};
23+
render() {
24+
app = this;
25+
return <Text text={this.state.step} />;
26+
}
27+
}
28+
29+
const root = ReactNoop.createRoot();
30+
await ReactNoop.act(async () => {
31+
root.render(<App />);
32+
});
33+
expect(Scheduler).toHaveYielded([0]);
34+
35+
await ReactNoop.act(async () => {
36+
app.setState({step: 1}, () =>
37+
Scheduler.unstable_yieldValue('Callback 1'),
38+
);
39+
ReactNoop.flushSync(() => {
40+
app.setState({step: 2}, () =>
41+
Scheduler.unstable_yieldValue('Callback 2'),
42+
);
43+
});
44+
});
45+
expect(Scheduler).toHaveYielded([2, 'Callback 2', 2, 'Callback 1']);
46+
});
47+
});

0 commit comments

Comments
 (0)