Skip to content

fix(editor): a composition always ends (iOS) - #19

Merged
SamTV12345 merged 2 commits into
mainfrom
fix/ios-composition
Nov 24, 2026
Merged

SamTV12345 merged 2 commits into
mainfrom
fix/ios-composition

Conversation

@SamTV12345

@SamTV12345 SamTV12345 commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Reported on an iPhone: the keyboard appears and typing works locally, but nothing reaches the server.

Cause:

  • During a composition (IME, dictation, iOS inline predictions), AceEditor does not incorporate local changes.
  • In addition, etherpad's collab_client waits for getInInternationalComposition() before applying NEW_CHANGES from the server.
  • iOS Safari does not always send compositionend, for example when the keyboard is dismissed, the field loses focus or a prediction is accepted.
  • The promise then stayed open forever: the text stayed local, nothing was sent, and nothing from others was applied.

Fix: a composition also ends

  • on blur of the editor,
  • on an input event with isComposing === false,
  • after 3 s without compositionstart or compositionupdate (watchdog, AceEditor.COMPOSITION_TIMEOUT_MS).

The end resolves the waiting promise and incorporates the text right away.

Test: new play test EpEditor › CompositionAlwaysEnds covering blur, a non-composing input (the text typed during the composition ends up in the editor), the watchdog and the normal compositionend. Locally all 139 tests pass.

After merge and release, etherpad-go needs the new version.


Generated by Claude Code

While a composition is open, local changes are not incorporated and
etherpad's collab client holds back NEW_CHANGES from the server. iOS
Safari does not always send compositionend (keyboard dismissed, focus
lost, inline prediction accepted), so the pad kept the typed text
locally and sent nothing - and applied nothing from others.

A composition now also ends on blur, on an input event with
isComposing === false, and after 3 s without composition activity.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012RMvvMtnCwj6ycD9fwLYVu
@qodo-code-review

Copy link
Copy Markdown

ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

End abandoned editor compositions on iOS

🐞 Bug fix 🧪 Tests 🕐 10-20 Minutes

Grey Divider

AI Description

• End compositions on blur, non-composing input, or three seconds without composition activity.
• Resume local change incorporation and unblock server changes when a composition ends.
• Add a Storybook play test for fallback endings and normal compositionend.
Merge Risk 🟡 Medium

Blast radius 🟢 Low 💥 1 capability

  • 1 affected end-to-end capability after fault-specific containment; implementation boundaries do not widen its functional scope.
  • The changed event state directly controls when the editor incorporates local DOM changes and when the public composition-wait state is cleared for collaboration consumers.
  • These are producer and consumer portions of one bounded editor synchronization behavior, not separate capabilities.
  • The repository exposes the state through EpEditor, while any external collaboration caller is outside the snapshot.
Sources

src/editor/AceEditor.ts[3243-3258]

    // Composition events (IME input, dictation, and iOS inline predictions).
    //
    // While a composition is open, local changes are not incorporated and
    // NEW_CHANGES from the server wait (collab_client awaits
    // getInInternationalComposition). iOS Safari does not always send
    // compositionend - e.g. when the keyboard is dismissed, the field loses
    // focus or a prediction is accepted - which left the pad "typing" locally
    // while nothing reached the server. So a composition also ends on blur, on
    // an input event that is no longer composing, and after a few seconds
    // without any composition activity. A pause alone does not prove the
    // composition is over, so composition activity after the watchdog fired
    // (compositionupdate or a composing input event) opens it again.
    this.targetBody.addEventListener('compositionstart', () => this.beginComposition());
    this.targetBody.addEventListener('compositionupdate', () => this.beginComposition());
    this.targetBody.addEventListener('compositionend', () => this.endComposition());
    this.targetBody.addEventListener('blur', () => this.endComposition());

src/editor/AceEditor.ts[3188-3199]

    // Input event - schedule incorporateUserChanges. An input that is no
    // longer part of a composition also ends one that never got its
    // compositionend (see below).
    this.targetBody.addEventListener('input', (e) => {
      const composing = (e as InputEvent).isComposing;
      if (composing === true) {
        this.beginComposition();
      } else if (this.inInternationalComposition && composing === false) {
        this.endComposition();
      }
      this.idleWorkTimer.atMost(0);
    });
Behavioral complexity 🔴 High 🧩 Interacting branches, Concurrent ordering

  • Before: composition tracking used a one-shot compositionstart listener that created a promise resolved only by the next compositionend.
  • After: composition state is created or reopened by multiple event types, can be ended by compositionend, blur, a non-composing input, or a timer, and has a separately resettable watchdog.
  • New correctness conditions are that the active promise and watchdog remain coherent across event/timer races, that ending resolves and clears the current state exactly once, that activity after a watchdog expiry can reopen the state, and that idle incorporation occurs only after the intended composition boundary.
  • The timer and promise use existing primitives, but their new interaction with browser event ordering materially changes the state machine.
Sources

src/editor/AceEditor.ts[3188-3199]

    // Input event - schedule incorporateUserChanges. An input that is no
    // longer part of a composition also ends one that never got its
    // compositionend (see below).
    this.targetBody.addEventListener('input', (e) => {
      const composing = (e as InputEvent).isComposing;
      if (composing === true) {
        this.beginComposition();
      } else if (this.inInternationalComposition && composing === false) {
        this.endComposition();
      }
      this.idleWorkTimer.atMost(0);
    });

src/editor/AceEditor.ts[3243-3258]

    // Composition events (IME input, dictation, and iOS inline predictions).
    //
    // While a composition is open, local changes are not incorporated and
    // NEW_CHANGES from the server wait (collab_client awaits
    // getInInternationalComposition). iOS Safari does not always send
    // compositionend - e.g. when the keyboard is dismissed, the field loses
    // focus or a prediction is accepted - which left the pad "typing" locally
    // while nothing reached the server. So a composition also ends on blur, on
    // an input event that is no longer composing, and after a few seconds
    // without any composition activity. A pause alone does not prove the
    // composition is over, so composition activity after the watchdog fired
    // (compositionupdate or a composing input event) opens it again.
    this.targetBody.addEventListener('compositionstart', () => this.beginComposition());
    this.targetBody.addEventListener('compositionupdate', () => this.beginComposition());
    this.targetBody.addEventListener('compositionend', () => this.endComposition());
    this.targetBody.addEventListener('blur', () => this.endComposition());
Potential damage 🟡 Medium 🩹 Temporary loss

  • If the changed lifecycle handling regresses by leaving the composition state active, local edits can remain unincorporated and collaboration consumers can continue waiting for composition completion.
  • The source shows that idle work explicitly defers incorporation while the state is active, and the new termination paths are intended to release it.
  • This is conditionally recoverable through a later qualifying event or timer; a page/editor reset can restore operation, but the source does not establish automatic repair of any external collaboration state that may have been delayed.
  • Recoverable after a correct termination event, subsequent watchdog expiry, or editor reset.
  • A code revert restores the previous event behavior but does not itself compensate for collaboration effects already delayed or applied.
  • No persistent-state repair or external compensation mechanism is established in this repository.
Sources

src/editor/AceEditor.ts[3188-3199]

    // Input event - schedule incorporateUserChanges. An input that is no
    // longer part of a composition also ends one that never got its
    // compositionend (see below).
    this.targetBody.addEventListener('input', (e) => {
      const composing = (e as InputEvent).isComposing;
      if (composing === true) {
        this.beginComposition();
      } else if (this.inInternationalComposition && composing === false) {
        this.endComposition();
      }
      this.idleWorkTimer.atMost(0);
    });

src/editor/AceEditor.ts[3243-3258]

    // Composition events (IME input, dictation, and iOS inline predictions).
    //
    // While a composition is open, local changes are not incorporated and
    // NEW_CHANGES from the server wait (collab_client awaits
    // getInInternationalComposition). iOS Safari does not always send
    // compositionend - e.g. when the keyboard is dismissed, the field loses
    // focus or a prediction is accepted - which left the pad "typing" locally
    // while nothing reached the server. So a composition also ends on blur, on
    // an input event that is no longer composing, and after a few seconds
    // without any composition activity. A pause alone does not prove the
    // composition is over, so composition activity after the watchdog fired
    // (compositionupdate or a composing input event) opens it again.
    this.targetBody.addEventListener('compositionstart', () => this.beginComposition());
    this.targetBody.addEventListener('compositionupdate', () => this.beginComposition());
    this.targetBody.addEventListener('compositionend', () => this.endComposition());
    this.targetBody.addEventListener('blur', () => this.endComposition());
Assessed commit 154d48e
Diagram

graph TD
  DOM["Editor events"] --> Signals["End signals"] --> Open{"Composition open?"} -->|yes| End["Close composition"] --> Promise["Waiting promise"] --> Client["Collab client"]
  End --> Idle["Idle incorporation"]
Loading
High-Level Assessment

Keep the centralized composition-ending path with event-based fallbacks and a watchdog. Event-only handling cannot recover when Safari sends no further event, while incorporating changes during an active composition risks processing incomplete text.

Files changed (2) +113 / -10

Bug fix (1) +54 / -10
AceEditor.tsRecover compositions that never receive compositionend +54/-10

Recover compositions that never receive compositionend

• Centralizes composition cleanup so every ending resolves the waiting promise and schedules local change incorporation. Adds blur and non-composing input fallbacks plus a three-second inactivity watchdog refreshed by composition activity.

src/editor/AceEditor.ts

Tests (1) +59 / -0
EpEditor.stories.tsExercise composition-ending fallbacks +59/-0

Exercise composition-ending fallbacks

• Adds a Storybook play test for blur, non-composing input, watchdog expiry, and normal compositionend. It also checks that text typed during composition is incorporated after the fallback ending.

stories/EpEditor.stories.ts

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Uncommitted text reaches collaborators ✓ Resolved
Description
armCompositionWatchdog() calls endComposition() after three seconds without a composition event,
even when the browser's composition is still active. A user who pauses while composing—or continues
receiving composing input without a compositionupdate—then has subsequent edits incorporated and
exposed to collaboration before the eventual compositionend.

Grey Divider

Tip of the day
💡 Did you know, you can show, collapse, or hide each part of a finding: code, evidence, and all

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

… closed

A pause longer than the watchdog timeout does not prove the composition is
over. compositionupdate and composing input events now re-open it, so text
that is still being composed is not incorporated before the real
compositionend. Addresses the Qodo review on #19.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012RMvvMtnCwj6ycD9fwLYVu
@SamTV12345
SamTV12345 merged commit ada7e2a into main Nov 24, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant