Skip to content

Flare: change flushDiscreteUpdates invariant to warning #15702

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions packages/react-dom/src/__tests__/ReactDOMFiber-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1026,15 +1026,9 @@ describe('ReactDOMFiber', () => {

it('should not update event handlers until commit', () => {
let ops = [];
let eventErrors = [];
const handlerA = () => ops.push('A');
const handlerB = () => ops.push('B');

spyOnProd(console, 'error');
window.addEventListener('error', e => {
eventErrors.push(e.message);
});

class Example extends React.Component {
state = {flip: false, count: 0};
flip() {
Expand All @@ -1052,7 +1046,11 @@ describe('ReactDOMFiber', () => {
class Click extends React.Component {
constructor() {
super();
node.click();
expect(() => {
node.click();
}).toWarnDev(
'Warning: unstable_flushDiscreteUpdates: Cannot flush updates when React is already rendering.',
Copy link
Collaborator

@acdlite acdlite May 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should bikeshed this message before it hits open source

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave you the key to the bikeshed. Help yourself.

);
}
render() {
return null;
Expand Down Expand Up @@ -1096,16 +1094,12 @@ describe('ReactDOMFiber', () => {

// Because the new click handler has not yet committed, we should still
// invoke B.
expect(ops).toEqual([]);
expect(ops).toEqual(['B']);
ops = [];

// Any click that happens after commit, should invoke A.
node.click();
expect(ops).toEqual(['A']);
expect(eventErrors[0]).toEqual(
'unstable_flushDiscreteUpdates: Cannot flush ' +
'updates when React is already rendering.',
);
});

it('should not crash encountering low-priority tree', () => {
Expand Down
13 changes: 8 additions & 5 deletions packages/react-reconciler/src/ReactFiberScheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -577,11 +577,14 @@ export function flushDiscreteUpdates() {
return;
}
if (workPhase === RenderPhase) {
invariant(
false,
'unstable_flushDiscreteUpdates: Cannot flush updates when React is ' +
'already rendering.',
);
if (__DEV__) {
warning(
false,
'unstable_flushDiscreteUpdates: Cannot flush updates when React is ' +
'already rendering.',
);
}
return;
}
flushPendingDiscreteUpdates();
if (!revertPassiveEffectsChange) {
Expand Down