Skip to content

Port upstream flush before save guard#75

Merged
Renakoni merged 2 commits into
mainfrom
sync/upstream-4859-flush-before-save
Jul 9, 2026
Merged

Port upstream flush before save guard#75
Renakoni merged 2 commits into
mainfrom
sync/upstream-4859-flush-before-save

Conversation

@Renakoni

@Renakoni Renakoni commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Upstream

Ports the Android-relevant behavior from marktext/marktext#4859: marktext/marktext#4859

Upstream fixed a save-path race where Muya can still have a same-frame edit queued in its rAF/json-state batch when the host snapshots markdown for persistence.

Android relevance

Android does not have the desktop Pinia FILE_SAVE / IPC path, but it does read editor.getMarkdown() for the same persistence boundary:

  • Android document save/autosave
  • local draft autosave
  • Save As / Save Copy flows
  • share flow
  • recovery-draft preservation before opening another document or leaving the editor

Muya already exposes flush() in this fork, and its own flushPendingOps.spec.ts proves getMarkdown() can be stale until flush() is called. This PR applies the upstream invariant to Android's save snapshots: flush first, then read markdown.

Changes

  • Add a small editor-owned readEditorMarkdownSnapshot() helper that can flush before reading and normalize the result.
  • Use flushed snapshots for Android save/copy/share/local-draft/recovery persistence paths.
  • Keep normal content-change reads unflushed, so regular editing still follows the existing event flow.
  • Add the missing flush() method to the local @muyajs/core type declaration.
  • Add focused unit coverage proving flush() is called before getMarkdown() for save-style snapshots, and that non-save reads remain unflushed.

Verification

  • pnpm vitest run src/features/editor/editorMarkdownSnapshot.test.ts src/features/android-documents/saveAndroidDocumentWorkflow.test.ts src/features/android-documents/saveLocalDraftToAndroidDocumentWorkflow.test.ts src/features/android-documents/saveAndroidDocumentCopyWorkflow.test.ts src/features/android-documents/shareAndroidMarkdownDocumentWorkflow.test.ts
  • pnpm build

@Renakoni Renakoni merged commit b2ebc9b into main Jul 9, 2026
4 checks passed
@Renakoni Renakoni deleted the sync/upstream-4859-flush-before-save branch July 9, 2026 01:18
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