Skip to content

Commit

Permalink
Don't flush interactive uncontrolled updates early
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Aug 29, 2018
1 parent 27fef7f commit 96cbe4d
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions packages/react-dom/src/events/ChangeEventPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ import {
} from './DOMTopLevelEventTypes';
import getEventTarget from './getEventTarget';
import isEventSupported from './isEventSupported';
import {getNodeFromInstance} from '../client/ReactDOMComponentTree';
import {
getNodeFromInstance,
getInstanceFromNode,
getFiberCurrentPropsFromNode,
} from '../client/ReactDOMComponentTree';
import * as inputValueTracking from '../client/inputValueTracking';
import {setDefaultValue} from '../client/ReactDOMFiberInput';

Expand Down Expand Up @@ -56,8 +60,25 @@ function createAndAccumulateChangeEvent(inst, nativeEvent, target) {
target,
);
event.type = 'change';
// Flag this event loop as needing state restore.
enqueueStateRestore(target);
const props = getFiberCurrentPropsFromNode(target);
if (props !== null) {
// This might be a controlled component, in which case
// we need to enqueue a state restore. We try to avoid
// it if possible because in async mode, this would
// force the interactive updates to flush early.
const type = props.type;
const needsRestore =
// Restore controlled inputs
props.value != null ||
// Restore controlled checkboxes
(type === 'checkbox' && props.checked != null) ||
// Restore all radios (because they affect cousins)
type === 'radio';
if (needsRestore) {
// Flag this event loop as needing state restore.
enqueueStateRestore(target);
}
}
accumulateTwoPhaseDispatches(event);
return event;
}
Expand Down

0 comments on commit 96cbe4d

Please sign in to comment.