Skip to content

Commit 4a1e6eb

Browse files
committed
Failing test: Updates "un-committed" when rebasing
Adds a failing test case where an update that was committed is later skipped over during a rebase. This should never happen.
1 parent 54f6673 commit 4a1e6eb

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

packages/react-reconciler/src/__tests__/ReactIncrementalUpdates-test.internal.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,4 +653,48 @@ describe('ReactIncrementalUpdates', () => {
653653
expect(Scheduler).toFlushAndYield(['Commit: goodbye']);
654654
});
655655
});
656+
657+
it('when rebasing, does not exclude updates that were already committed, regardless of priority', async () => {
658+
const {useState, useLayoutEffect} = React;
659+
660+
let pushToLog;
661+
function App() {
662+
const [log, setLog] = useState('');
663+
pushToLog = msg => {
664+
setLog(prevLog => (prevLog += msg));
665+
};
666+
667+
useLayoutEffect(
668+
() => {
669+
Scheduler.unstable_yieldValue('Committed: ' + log);
670+
if (log === 'B') {
671+
setLog(prevLog => (prevLog += 'C'));
672+
}
673+
},
674+
[log],
675+
);
676+
677+
return log;
678+
}
679+
680+
const root = ReactNoop.createRoot();
681+
await ReactNoop.act(async () => {
682+
root.render(<App />);
683+
});
684+
expect(Scheduler).toHaveYielded(['Committed: ']);
685+
expect(root).toMatchRenderedOutput('');
686+
687+
await ReactNoop.act(async () => {
688+
pushToLog('A');
689+
ReactNoop.discreteUpdates(() => {
690+
pushToLog('B');
691+
});
692+
});
693+
expect(Scheduler).toHaveYielded([
694+
'Committed: B',
695+
'Committed: BC',
696+
'Committed: ABC',
697+
]);
698+
expect(root).toMatchRenderedOutput('ABC');
699+
});
656700
});

0 commit comments

Comments
 (0)