Fixed skipped keys in controlled components on IE #127
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes a problem when fast typing results in some keys gone missing in IE (even relatively contemporary IE 11)
tonsky/rum#86
reagent-project/reagent#253
What happens is on IE
onChange
event is fired out of order, with a significant delay (not sure if it’s a React trying to “normalize” IE behaviour by polling it with a timeout or an actual IE problem). That causes problems with re-render happening onrequestAnimationFrame
.Imagine a component:
Typical order of events, if I type "QW" into the input:
Q
W
Q
on-change
callback is called,*value
got reset toQ
on-change
should fire, setting*value
toQW
and causing no problems. Not on IEcomp
is re-rendered. Notice that the*value
still holdsQ
, but actual value of input in DOM isQW
. Secondon-change
has not fired yet, but value has already changed without us noticing it.<input value=Q>
while on DOM it’s<input value=QW>
. Diffing kicks in, React resets value back toQ
.on-change
never fires, cursor position got messed up, etc.This patch changes wrapped components, adds detecting of this situation (onChange and actual DOM value disagreeing) and works around that.