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

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. .

@ellatrix ellatrix added [Type] Bug An existing feature does not function as intended [Feature] Rich Text Related to the Rich Text component that allows developers to render a contenteditable labels Dec 16, 2019
@ellatrix ellatrix requested a review from mcsf December 16, 2019 14:38
Copy link
Contributor

@mcsf mcsf left a comment

Choose a reason for hiding this comment

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

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.
Copy link
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

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
@ellatrix ellatrix deleted the fix/is-composing-safari branch December 17, 2019 11:03
@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
Labels
[Feature] Rich Text Related to the Rich Text component that allows developers to render a contenteditable [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(Safari) Dead key accents break out of inline formatting
3 participants