software-mansion / software-mansion/react-native-enriched-html

[Android] Inline styles are stripped from previously-styled text when toggling a style OFF mid-word with predictive text enabled

Open
#734 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C
Stars
1.4k
Forks
66
Avg merge
4d 19h
Merged PRs (30d)
11

Description

Description

On Android, when predictive text / word suggestions are enabled on the soft keyboard (so the current word is held in an active IME composing region), toggling an inline style (bold / italic / underline / strikethrough) OFF and then continuing to type without a space causes the previously styled text in the same composing word to lose its style.

The style formatting bit is dropped, not just the visual rendering — the earlier characters that were styled become unstyled.

Steps to reproduce

Using the library's example app (raw <EnrichedTextInput>, no wrapper):

  1. Use a soft keyboard with predictive text / suggestions ON (e.g. Gboard default).
  2. Focus the editor and start typing a word, e.g. abc.
  3. Toggle bold ON, continue typing without a spacedef (now def is bold, still one composing word abcdef).
  4. Toggle bold OFF, continue typing without a spaceghi.
  5. Observe the result.

Expected: def stays bold; only ghi is unstyled → abc + def + ghi.

Actual: the previously bolded def loses its bold → the whole word renders unstyled.

Notes:

  • Reproduces the same way for italic / underline / strikethrough.
  • The trigger is the active composing region covering the styled text. If the IME commits each key immediately (composing=[-1,-1]), the bug does not occur. hw.keyboard turned out not to be the determining factor.
  • Typing a space (which commits the composing region) before toggling avoids it.

Environment

  • react-native-enriched-html: reproduced on latest main (cloned repo example app) and on 1.1.0-nightly-20260724-982c0ca15.
  • React Native: 0.86
  • Platform: Android only (iOS unaffected).
  • Reproduced on:
    • Samsung Galaxy S9 — Android 10, Samsung Keyboard, English
    • Samsung Galaxy S20 Ultra — Android 13, Samsung Keyboard, English
    • Emulator: Pixel 8a, API 36 (Android 16), Microsoft SwiftKey, English

Correction (2026-08-03). This section originally said "Gboard predictive text / suggestions ON" for all three environments. That was wrong: Gboard is not installed on the Galaxy devices, which use Samsung Keyboard. With Gboard in English the bug does not reproduce at all — Gboard sends every character via commitText with no composing region. It reproduces with any IME that keeps an active composing region, e.g. Microsoft SwiftKey on a plain emulator. See the analysis in the comments below.

Likely cause (hypothesis)

While an IME composing region is active over the text, applying/removing an inline style span interacts with the composing region such that when the composing text is subsequently replaced (setComposingTextSpannableStringBuilder.replace), the character-level style spans within the replaced range are dropped.

Possible directions:

  • Commit the composing region (InputConnection.finishComposingText()) before applying/removing an inline-style span, so the style is applied to committed (non-composing) text.
  • Or re-apply / preserve existing character-level style spans across the composing-text replacement (span flags / re-span after setComposingText).

https://github.com/user-attachments/assets/0532fc28-f8b0-42d8-935d-033e1f647ca8

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce this in the example app using raw and an IME that keeps an active composing region, such as SwiftKey. Start by tracing the Android InputConnection handling around setComposingText and SpannableStringBuilder.replace. Done means toggling an inline style off mid-word preserves the earlier styled characters for bold, italic, underline, and strikethrough.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, react-native
Domain
mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.