lexical icon indicating copy to clipboard operation
lexical copied to clipboard

Bug: composition is broken with non-gboard android keyboard

Open vchirikov opened this issue 1 year ago • 6 comments

Image

Lexical version: 0.33.1

Steps To Reproduce

  1. Install yandex keyboard
  2. Type one word (get compositionend on that word)
  3. Type another word (get compositionend on that word too)
  4. return selection via click on first word (you'll fire compositionend)
  5. click on last character/end of the line

The current behavior

$internalResolveSelectionPoint return offset > than node.getTextContentSize() (because The last word is compositing with ZERO_WIDTH_SPACE in the DOM)

App.tsx:206 Uncaught Error: $validatePoint: anchor point.offset > node.getTextContentSize() (10 > 9)
    at formatDevErrorMessage (formatDevErrorMessage.ts:12:9)
    at $validatePoint (LexicalSelection.ts:2696:23)
    at $internalResolveSelectionPoints (LexicalSelection.ts:2497:7)
    at $internalCreateRangeSelection (LexicalSelection.ts:2655:35)
    at LexicalEvents.ts:1269:30
    at $beginUpdate (LexicalUpdates.ts:949:5)
    at updateEditorSync (LexicalUpdates.ts:1062:5)
    at HTMLDocument.onDocumentSelectionChange (LexicalEvents.ts:1261:5)

The expected behavior

nothing is broken, you shouldn't get errors in console

Impact of fix

Not all phones use GBoard (e.g. Honor or some of Huawei), composition bugs affects many users.

vchirikov avatar Jul 22 '25 10:07 vchirikov

Another issue with this keyboard is inside logic of onCompositionStart which call dispatchCommand(editor, CONTROLLED_TEXT_INSERTION_COMMAND, COMPOSITION_START_CHAR).

Double click/tap on word (to select it) causes replacing all selection range with \u200b (deleting the selected word)

This is how it looks (I added console.logs to show clearly what happened):

Image

Overall including #7649 lexical with all its hacks around seems like completely broken on non-gboard keyboards.

Maybe we can check composition approach of ckeditor or even slate, because I don't find so weird behavior there.

vchirikov avatar Jul 22 '25 10:07 vchirikov

Link here https://github.com/facebook/lexical/pull/7725 , because looks like the first part of the issue should be fixed with it (will test after release). The second part is not (double tap/click => selection replaced with ZERO_WIDTH_SPACE).

vchirikov avatar Jul 24 '25 22:07 vchirikov

The playground is built with the latest commit from main, you should be able to test it there now. You can also test the playground preview link from any PR (even after it is closed)

etrepum avatar Jul 24 '25 22:07 etrepum

@etrepum I tested latest commit (f104810d6) locally and confirm #7725 works fine. However, the issue with selection still exist. Can I help with an additional trace of events or some logs to resolve it?

vchirikov avatar Jul 25 '25 06:07 vchirikov

What this really needs is for someone with an Android device and enough motivation to get in there and start debugging and fixing these issues. There isn't really any infrastructure for capturing/replaying input events that would make "debugging by email" feasible.

etrepum avatar Jul 25 '25 06:07 etrepum

I tested this on Android (Samsung Galaxy, Yandex Keyboard, Chrome) with the latest playground.

Bug A (offset crash): Confirmed fixed by #7725.

Bug B (double-tap ZWSP replacement): Could not reproduce on current main. Double-tapping a word correctly selects it without replacing the text with ZWSP.

There is some residual flickering in the tree view when toggling Bold (empty bold text node appearing/disappearing rapidly), which shares the same root cause as #7649 (formatMismatch ZWSP insertion path in $handleCompositionStart). The final result is usually correct.

Closing this as the original reported issues are resolved. If you can still reproduce bug B on the latest playground, please reopen.

mayrang avatar Jul 01 '26 14:07 mayrang