Skip to content

fix(pptx): flush pending edits before saving - #21

Open
mkroemer wants to merge 1 commit into
p10node:mainfrom
mkroemer:fix/issue18-flush-pptx-save
Open

mkroemer wants to merge 1 commit into
p10node:mainfrom
mkroemer:fix/issue18-flush-pptx-save

Conversation

@mkroemer

Copy link
Copy Markdown
Contributor

Saving immediately after editing slide text could serialize the file before the editor's debounced commit, omitting the latest edit while clearing dirty state. Save now flushes and awaits pending PPTX edits before serialization.

Failed editor commits remain retryable, overlapping saves are guarded, and edits made during a save or in a replacement document retain their dirty state. Original downloads and print/export use the same flush hook.

Fixes #18. This is a standalone fix against main, separate from the controller formatting feature in #9.

Validation with Bun 1.4.4: typecheck, full build, and 540 unit tests passed. Seven save-race browser regressions, ten existing PPTX editing/focus tests, 94 cross-format/menu/permissions/viewer tests, and four source-save compatibility checks passed. The immediate-save regression fails on unchanged main.

Await debounced and in-flight slide edits through FileOps before save and export. Retain failed commits for retry, guard overlapping saves and stale document completions, and preserve dirty state for edits made during save. Add browser regressions for immediate text/format saves, failures, retries, source replacement, unmount and exports.

@pierreneter pierreneter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for picking up #18. The lost-edit case itself is fixed, but the commit queue and the save session bring regressions that are worse than the original bug, so I can't merge this as it is. Line numbers are at d98c44e.

Reproduced:

  1. src/react/pptx/PptxEditor.ts:253: commit() now queues a snapshot behind an in-flight setText, so end() no longer guarantees that the text reaches the worker before the structural op that follows it. With one debounce commit in flight: type more, then delete, move or duplicate a slide. The worker gets setText(A), pptx.slides, setText(B) with the old slide index, so B lands on another slide or throws No slide #n. In a collab session the stale index is what gets broadcast.
  2. PptxEditor.ts:264: a snapshot that fails stays at the head of the queue and is retried forever. These failures are deterministic (Shape n not found, a collab session in error), so one failure blocks every later commit, and flush() rejects on every Save, Download, PDF and Print until reload. Before, the failed edit was dropped and Save still worked.
  3. src/react/DocViewer.tsx:189: the save session is keyed on opened and client, so the live-preview reload of a Markdown / HTML / SVG source counts as a new document. sample.md, Code pane, type, Ctrl+S with an onSave slower than the 350 ms preview debounce:
    • dirty is never cleared (onDirtyChange gives [true], base gives [true, false]);
    • a rejected onSave shows no toast and calls no onError;
    • the Save button is re-enabled mid-save, so a second click runs onSave twice in parallel.
  4. DocViewer.tsx:356: the revision is captured before the worker has acknowledged edits that are already posted. XLSX: type a cell, Enter, Ctrl+S before the xlsx.set reply. The saved file contains the edit, but the late reply bumps the revision and the viewer stays dirty. Same for PPTX shape and slide ops.

From reading, not run:

  • flush() loops on changedSinceCommit, which commit() only clears while a shape is active. I found no UI path into that state today, but if it is reached, Save spins forever on microtasks.
  • Download original now shares the saving guard with the host's Save, so each silently cancels the other.
  • The catch returns silently whenever the session is no longer live, which also swallows a real onSave rejection for a document the user has just replaced.

A different shape may be simpler: a pending-work barrier in DocumentClient in front of save and pptx.slide, or committing on each edit as DocxEditor does. That also covers a host that calls client.call('save') itself, which a per-view flush hook does not, and it needs no queue or retry.

This branch has not been deployed

No deployments
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.

PPTX: saving before the text-edit debounce omits the latest edit

2 participants