Skip to content

Pending changeset is never sent while history mode is open (lost if the tab is closed) #8595

Backlog

Description

@TomNewChao

Describe the bug

If the user switches to in-pad history mode while ACE still has an uncommitted changeset, the pending changeset is never sent to the server for as long as history mode stays open. The local buffer survives and the changeset flushes ~immediately after returning to live mode — but if the user closes the tab (or the browser crashes) while browsing history, the edit is permanently lost.

Verified at the WebSocket layer: after typing and entering history mode, zero USER_CHANGES frames go out for 10+ seconds; clicking "Return to live" produces the send 0.3s later.

Observed in the mobile layout during manual testing, then isolated: it is not mobile-specific and not deterministic — it is a race between the ACE commit timer and the history-mode switch (roughly a few hundred ms window; immediate switch right after typing hits it, a ~1s delay avoids it). At desktop viewport the same immediate flow usually wins the race, which is why it is easy to miss.

To Reproduce

  1. Open a pad, click into the text, type a sentence.
  2. Immediately click the history button (do not wait).
  3. While in history mode, check the pad server-side (e.g. GET /p/<pad>/export/txt): the typed sentence is absent.
  4. Click "Return to live": the sentence reappears and is now committed server-side.
  5. If instead of step 4 the tab is closed while in history mode, the sentence is gone for good.

Reproduced with Playwright (Chromium) driving real clicks/keys — flaky (~30-50% of attempts with an immediate switch), independent of viewport width.

Suspected mechanism

collab_client's commit pump (handleUserChanges) reschedules itself on every exit path except the inInternationalComposition guard (collab_client.ts:98-102), and its only revival is the next user-change notification (editor.setUserChangeNotificationCallback(handleUserChanges)). Entering history mode appears to break that revival chain (focus/composition/collapsed-toolbar side effects of the switch are candidates — not yet pinned down). Dispatching a synthetic compositionend into the editor does not revive a stalled pump, so the trigger is subtler than a stuck composition flag.

Data is not discarded: the buffer survives in the hidden editor and commits on return — so the loss surface is limited to "tab closed / crash while in history mode with a pending commit".

Expected behavior

Entering history mode should flush any pending changeset first (or the commit pump should keep running while history mode is open), so an edit made right before scrubbing history cannot be lost.

Additional context

Activity

  1. TomNewChao commented on Dec 1, 2026

    @TomNewChao
    Author

    Narrowed the stall point with a runtime probe (Playwright, window.pad.collabClient exposed):

    • In the stalled state, collabClient.hasUnacceptedCommit() returns false — meaning stateMessage was never set (collab_client.ts:141), i.e. handleUserChanges died before the prepare/send stage. Returning to live revives the pump (stateMessage gets set, the send fires ~0.3s later, server receives the edit).

    So the pump's scheduling chain breaks somewhere between the user-change notification (editor.setUserChangeNotificationCallback, collab_client.ts:527) and the send — i.e. it stopped taking the re-scheduling exits at handleUserChanges collab_client.ts:97-160. handleUserChanges has exactly two exits that do not schedule the next run:

    1. the editor.getInInternationalComposition() guard (lines 98-102) — relies on "composition end will call it again"
    2. the empty-changeset path (line 137: prepareUserChangeset() returns no changeset → sentMessage stays false → falls through with no setTimeout)

    Both silently stop the pump, relying on the next setUserChangeNotificationCallback to revive it — which evidently never fires while history mode is open. Entering history mode hides #editorcontainer (display:none) and relayouts the toolbar; one of those side effects appears to swallow the notification/kick. Synthetic compositionend dispatched into the editor did not revive a stalled pump, so it is not (just) a stuck composition flag.

    Repro remains as described above (flaky ~30-50% with an immediate history switch after typing; hasUnacceptedCommit() probe makes it fully detectable).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions