Flare: change flushDiscreteUpdates invariant to warning (#15702)
Dominic Gannaway committed
May 22, 2019 at 01:09 UTC
e180f656f364cd8a0e8441cb268f99a312265b21
2 files changed
+14
-17
packages/react-dom/src/__tests__/ReactDOMFiber-test.js
+6
-12
@@ -1026,15 +1026,9 @@ describe('ReactDOMFiber', () => {
1026
1027
it('should not update event handlers until commit', () => {
1028
let ops = [];
1029
- let eventErrors = [];
1029
const handlerA = () => ops.push('A');
1030
const handlerB = () => ops.push('B');
1031
1033
- spyOnProd(console, 'error');
1034
- window.addEventListener('error', e => {
1035
- eventErrors.push(e.message);
1036
- });
1037
-
1032
class Example extends React.Component {
1033
state = {flip: false, count: 0};
1034
flip() {
@@ -1052,7 +1046,11 @@ describe('ReactDOMFiber', () => {
1046
class Click extends React.Component {
1047
constructor() {
1048
super();
1055
- node.click();
1049
+ expect(() => {
1050
+ node.click();
1051
+ }).toWarnDev(
1052
+ 'Warning: unstable_flushDiscreteUpdates: Cannot flush updates when React is already rendering.',
1053
+ );
1054
}
1055
render() {
1056
return null;
@@ -1096,16 +1094,12 @@ describe('ReactDOMFiber', () => {
1094
1095
// Because the new click handler has not yet committed, we should still
1096
// invoke B.
1099
- expect(ops).toEqual([]);
1097
+ expect(ops).toEqual(['B']);
1098
ops = [];
1099
1100
// Any click that happens after commit, should invoke A.
1101
node.click();
1102
expect(ops).toEqual(['A']);
1105
- expect(eventErrors[0]).toEqual(
1106
- 'unstable_flushDiscreteUpdates: Cannot flush ' +
1107
- 'updates when React is already rendering.',
1108
- );
1103
});
1104
1105
it('should not crash encountering low-priority tree', () => {
packages/react-reconciler/src/ReactFiberScheduler.js
+8
-5
@@ -577,11 +577,14 @@ export function flushDiscreteUpdates() {
577
return;
578
}
579
if (workPhase === RenderPhase) {
580
- invariant(
581
- false,
582
- 'unstable_flushDiscreteUpdates: Cannot flush updates when React is ' +
583
- 'already rendering.',
584
- );
580
+ if (__DEV__) {
581
+ warning(
582
+ false,
583
+ 'unstable_flushDiscreteUpdates: Cannot flush updates when React is ' +
584
+ 'already rendering.',
585
+ );
586
+ }
587
+ return;
588
}
589
flushPendingDiscreteUpdates();
590
if (!revertPassiveEffectsChange) {