Repository navigation
fix(editor): save rich-markdown preview edits on blur, switch, and quit before the serialize debounce (#9730) - #9823
Conversation
📝 WalkthroughWalkthroughRich Markdown preview editing now tracks dirty state in a ref and exposes a flush-and-save callback. Dirty previews flush pending editor changes and request a file save on blur and component unmount, while clean previews do nothing. New tests cover dirty blur, dirty unmount, and clean lifecycle behavior before debounce publication. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/renderer/src/components/editor/rich-markdown-preview-save.test.ts (1)
50-54: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winExercise the registered serialization flush.
registerPendingEditorFlushandflushPendingEditorChangeare both no-op mocks, so these tests do not prove that"edited"reachesonContentChangebefore saving. Retain the registered callback, invoke it from the flush mock, and assert the content publication; otherwise a broken registration or file-ID mismatch can still pass while saving stale content.Also applies to: 194-224
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: da920391-928b-42ce-b6f9-41b68ac16efa
📥 Commits
Reviewing files that changed from the base of the PR and between 261a7b7 and 42358342aea57282724a174e0340eba01b7195cb.
📒 Files selected for processing (3)
src/renderer/src/components/editor/RichMarkdownEditor.tsxsrc/renderer/src/components/editor/rich-markdown-editor-config.tssrc/renderer/src/components/editor/rich-markdown-preview-save.test.ts
4235834 to
56ef0ed
Compare
|
Hi @rodboev , @brennanb2025 , thanks for the fix! Just a quick heads-up that this branch currently has conflicts that need to be resolved and a workflow awaiting approval. Could you please take a look when you have a moment? |
56ef0ed to
a4e0da7
Compare
a4e0da7 to
58986b7
Compare
|
Rebased onto current Focused reruns on the new head passed for the rich-preview regression test, Greptile is running on the new head now. |
brennanb2025
left a comment
There was a problem hiding this comment.
Nice focused fix. Blur now flushes pending Rich Markdown serialization into the existing draft/autosave path, preserving fast edits without bypassing autosave suspension or changed-on-disk protection. Verified with the 21-test focused suite, typecheck/lint, and live Electron validation.
| it('flushes pending serialization when the rich editor blurs', () => { | ||
| const setMarkdownEditorFocused = vi.fn() | ||
| vi.stubGlobal('window', { | ||
| api: { ui: { setMarkdownEditorFocused } } | ||
| }) | ||
| const flushPendingSerialization = vi.fn() | ||
| const clearAnnotationTarget = vi.fn() | ||
| const config = createRichMarkdownEditorConfig( | ||
| createConfigParams({ clearAnnotationTarget, flushPendingSerialization }) | ||
| ) | ||
|
|
||
| config.onBlur?.({} as never) | ||
|
|
||
| expect(setMarkdownEditorFocused).toHaveBeenCalledWith(false) | ||
| expect(clearAnnotationTarget).toHaveBeenCalledOnce() | ||
| expect(flushPendingSerialization).toHaveBeenCalledOnce() | ||
| }) |
There was a problem hiding this comment.
Testing checklist references a non-existent file
The PR description's testing checklist checks off running rich-markdown-preview-save.test.ts, but that file does not exist anywhere in the repository. The PR notes also describe the regression harness as one that "mounts RichMarkdownEditor, drives its real rich-editor config through an edit, advances fake timers by 299 ms" — but the actual test added here exercises only createRichMarkdownEditorConfig directly with a mock flushPendingSerialization. Anyone trying to reproduce the listed test run would get an error on that command.
Greptile SummaryThis PR fixes a data-loss window in the rich-markdown preview editor where fast edits could be dropped if the user blurred the editor, switched tabs, or quit before the 300 ms serialization debounce fired. The fix adds a single
Confidence Score: 4/5Safe to merge. The production change is a single-line addition to an existing event handler; the flush function is idempotent and cannot cause duplicate serialization. The core fix is minimal and correct. The PR testing checklist checks off a test file that does not exist in the repository, meaning the described integration test was never run. The added unit test only verifies the mock is called, not that the full save pipeline completes. Files Needing Attention: No files require special attention beyond the discrepancy noted in the test file checklist reference.
|
| Filename | Overview |
|---|---|
| src/renderer/src/components/editor/rich-markdown-editor-config.ts | Added params.flushPendingSerialization() call to onBlur handler, mirroring the existing unmount path. The change is minimal, correct, and idempotent since flushPendingSerialization short-circuits when no timer is pending. |
| src/renderer/src/components/editor/rich-markdown-editor-config.test.ts | Added afterEach(vi.unstubAllGlobals) cleanup and a new test that verifies flushPendingSerialization is called on blur. Test is correct and covers the new behavior, but the PR checklist references a different test file (rich-markdown-preview-save.test.ts) that does not exist. |
Reviews (1): Last reviewed commit: "fix(editor): keep rich markdown blur sav..." | Re-trigger Greptile
…it before the serialize debounce (stablyai#9730) (stablyai#9823) * fix(editor): flush markdown preview saves before teardown (stablyai#9730) * fix(editor): keep rich markdown blur saves policy-safe --------- Co-authored-by: Brennan Benson <[email protected]>
Summary
Fast edits in Rich Markdown preview could remain inside the 300 ms serialization buffer when the editor blurred. The file was marked dirty, but the existing autosave controller did not yet have a draft to persist.
This PR flushes pending Rich Markdown serialization on blur so the existing draft and autosave pipeline handles the save:
Closes #9730.
Testing
pnpm typecheckpnpm lintoxfmt --checkPerformance and security
No new IPC, disk-write path, listener, polling loop, subprocess, cache, or trust boundary is introduced. Blur uses the existing bounded serialization flush.