Skip to content
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

RichText: fix isComposing for Safari #19171

Merged
merged 2 commits into from Dec 17, 2019
Merged

RichText: fix isComposing for Safari #19171

merged 2 commits into from Dec 17, 2019

Conversation

@ellatrix
Copy link
Member

ellatrix commented Dec 16, 2019

Description

Fixes #19161.

Apparently Safari doesn't support isComposing on an input event. See https://developer.mozilla.org/en-US/docs/Web/API/InputEvent/isComposing.
The solution is to set a flag on compositionstart and remove and compositionend.

Unfortunately, we cannot add an e2e test right now. See puppeteer/puppeteer#4981.

How has this been tested?

For an American keyboard:

  • Create a paragraph.
  • Press Cmd+B, then Alt+` , then type "a". "à" should be bold.

Screenshots

Types of changes

Bug fix

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR. .
@mcsf
mcsf approved these changes Dec 16, 2019
Copy link
Contributor

mcsf left a comment

This is great, thanks for the prompt fix!

document.removeEventListener( 'selectionchange', this.onSelectionChange );
// Do not trigger a change if characters are being composed. Browsers
// will usually emit a final `input` event when the characters are
// composed.

This comment has been minimized.

Copy link
@mcsf

mcsf Dec 16, 2019

Contributor

Thanks for all the comments. Maybe expand this one to reflect the current change, e.g.

… As of December 2019, Safari doesn't honour nativeEvent.isComposing.

Incidentally, that could make it easier — later on, in a year or ten — to know what workarounds can be eliminated in our code base.

This comment has been minimized.

Copy link
@ellatrix

ellatrix Dec 16, 2019

Author Member

Yes, I should add something here. I'm also wondering if I should still use nativeEvent.isComposing and fall back to this.isComposing. Normally compositionstop should fire, but who knows, if in some rare cases it doesn't, the value would be stuck at true until composing is started again. nativeEvent.isComposing is probably more reliable. On the other hand, always using this.isComposing will more quickly surface any bugs.

This comment has been minimized.

Copy link
@mcsf

mcsf Dec 17, 2019

Contributor

I don't oppose to listening to those two sources, but is there anything making you doubt of compositionstop's reliability? Since it's a proper SyntheticEvent, I would expect adequate browser support.

This comment has been minimized.

Copy link
@ellatrix

ellatrix Dec 17, 2019

Author Member

Yes, browser support is good, but I wouldn't be surprised if it's implemented slightly differently in browsers, just like the calling order of all these event handlers, or not called at all in some situations. Let's try this and keep an eye on reports.

@ellatrix ellatrix merged commit 8401390 into master Dec 17, 2019
2 checks passed
2 checks passed
pull-request-automation
Details
Travis CI - Pull Request Build Passed
Details
@ellatrix ellatrix deleted the fix/is-composing-safari branch Dec 17, 2019
@youknowriad youknowriad added this to the Gutenberg 7.2 milestone Jan 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.