Repository navigation
Description
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
- Open a pad, click into the text, type a sentence.
- Immediately click the history button (do not wait).
- While in history mode, check the pad server-side (e.g.
GET /p/<pad>/export/txt): the typed sentence is absent. - Click "Return to live": the sentence reappears and is now committed server-side.
- 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
- Found while working on the history-mode authors banner (History mode: authors of the viewed revision are only visible in the closed users popup #8593 / fix(pad): show revision authors in the history banner #8594); reproducible on current master.
- Happy to help verify a fix.
Activity
TomNewChao commentedon Dec 1, 2026
Narrowed the stall point with a runtime probe (Playwright,
window.pad.collabClientexposed):collabClient.hasUnacceptedCommit()returnsfalse— meaningstateMessagewas never set (collab_client.ts:141), i.e.handleUserChangesdied before the prepare/send stage. Returning to live revives the pump (stateMessagegets 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 athandleUserChangescollab_client.ts:97-160.handleUserChangeshas exactly two exits that do not schedule the next run:editor.getInInternationalComposition()guard (lines 98-102) — relies on "composition end will call it again"prepareUserChangeset()returns no changeset →sentMessagestays false → falls through with nosetTimeout)Both silently stop the pump, relying on the next
setUserChangeNotificationCallbackto 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. Syntheticcompositionenddispatched 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).