Temporarily uncontrol InputGroup during IME composition #4262
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.
Read facebook/react#3926 for full context on the issue.
Basically, while composing text using an IME, onChange events still fire for every keystroke.
From my testing, it seems that IF the InputGroup is controlled AND the
setState
call in the parent component occurs asynchronously, then the IME composition gets interrupted when the props change.You can reproduce this behaviour by replacing this line: https://github.com/palantir/blueprint/blob/develop/packages/docs-app/src/examples/core-examples/inputGroupExample.tsx#L58
with
to force an asynchronous update.
I'm not sure this is the right fix, but it's certainly simple. The proposal is that we temporarily stop controlling the input component while IME composition is occurring.
We purposefully continue sending onChange events during this time, since this matches what the behaviour would be in the uncontrolled case, and ensures that once we re-take control when composition ends, the parent component's state should be in-sync with whatever was in the input box as a result of composition.
I have tested in Chrome and Safari on MacOS, and both exhibit correct behaviour after this fix, even with the above hack to force asynchronous state changes.
That said, any behaviour like this has the potential to be fragile, so would appreciate any input from the team.
Checklist
Changes proposed in this pull request:
Temporarily relinquish control of input component during IME composition.
Reviewers should focus on:
How fragile this is likely to be. Are there any edge cases?
Screenshot
No visible changes.