Repository navigation
fix(platform): cancel pending Inbox editor work on teardown - #3578
Conversation
Sending from the Inbox reply box or New email remounts the Milkdown editor, and leaving a conversation unmounts it. Milkdown's listener hands an edit to the draft on a 200ms debounce after the last keystroke, and 7.20.0 never cancelled that debounce when the editor was destroyed. A send or a conversation switch inside the window ran the hand-off against the destroyed editor, whose paragraph serializer reads the removed editorView, and threw an uncaught `Context "editorView" not found` (#3567). Milkdown fixed exactly this upstream (Milkdown/milkdown#2356, #2384: the listener's view destroy cancels its debounce), released in 7.21.2. Move @milkdown/crepe, kit and react to 7.21.3, the release Renovate already queues for them and the newest past the 60-day stabilization window. Nothing else in the lockfile moves, and katex stays on its 0.16.47 override. The rest of 7.21 sanitizes link hrefs and SVG previews, keeps a Markdown mark open across the text nodes that share it, and adds an AI feature Crepe leaves off. The regression drives the real editor with a fake clock on the debounce: type, then send or leave while the hand-off is pending, wait for Milkdown's own destroy event, and run what was scheduled. On 7.20.0 both teardown cases throw the reported error; a control proves the same clock hands a live editor's edit to the draft.
yannickmonney
left a comment
There was a problem hiding this comment.
Reviewed 0db69bf3c330b21956ff4039e14f42aac6fdf71b against 44e0dcf254975286c0e9dea443b5cd1ca6b23347.
The three direct Milkdown packages and their locked family move together to 7.21.3. The regression covers both editor remount after Send and unmount on leaving, with a live-editor publication control so cancelling the pending callback cannot pass vacuously. The changed production surface is the dependency pin; the app editor implementation is unchanged.
I found no additional blocking code issue in this diff. A fresh React Doctor diff scan completed at 100/100 with no diagnostics (one changed source/test file). I did not rerun the Chromium lifecycle suite in this review, so this scan is not a substitute for that suite or the combined Inbox integration checks described above. CI still had pending image/smoke jobs at review time. No merge or deployment performed.
Summary
Sending from the Inbox reply box or New email remounts the Milkdown editor, and leaving a conversation unmounts it. Milkdown 7.20.0's listener plugin never cancelled its 200 ms draft-publication debounce when the editor was destroyed. A send or a conversation switch inside that window therefore ran the publication against the destroyed editor and threw an uncaught
MilkdownError: Context "editorView" not found(#3567). Upstream fixed exactly this (Milkdown/milkdown#2356, fix #2384, first released in 7.21.2). This moves@milkdown/crepe,@milkdown/kitand@milkdown/reactto 7.21.3 and adds a real-editor teardown regression.Closes #3567
Root cause
MessageEditorremounts itsMilkdownProviderafter a successful send, and the panel keys it by conversation.@milkdown/reactthen callseditor.destroy(), and the editor-view plugin's cleanup runsview.destroy()followed byctx.remove(editorViewCtx).@milkdown/plugin-listener7.20.0 schedulesdebouncedHandler(a lodash debounce, 200 ms) on every document-changing transaction. Its ProseMirror plugin view'sdestroyonly notified destroy listeners; it did not cancel the debounce (src/index.tsL165–194).serializer(doc)reaches the commonmark paragraphtoMarkdownrunner. That runner callsctx.get(editorViewCtx), which throwscontextNotFounduncaught inside the timer.debouncedHandler.cancel()in thatdestroy(upstreama1868c02a7).Why the upgrade rather than an app-side workaround
The debounce is private to the plugin. The app could only stop it by mutating Milkdown's listener internals or by swallowing serializer errors.
7.21.3 is the release Renovate's dependency dashboard (Dependency Dashboard #101) already queues for these three packages. It is also the newest one past the repo's 60-day minor stabilization window (released 2026-07-12; 7.22.x is still inside it).
Lockfile: only
@milkdown/*moves, plus kit's new@milkdown/plugin-diffand@milkdown/plugin-streaming. katex stays on the root0.16.47override; crepe calls onlykatex.renderandrenderToString. Milkdown's only consumer ismessage-editor.tsx.Upstream changes from 7.20.0 to 7.21.3, reviewed from source:
hrefsanitizing intoDOM, which also coversgetHTML(), plus an SVG-aware Mermaid sanitizer andrel="noopener noreferrer"on link previews;defaultFeatures.AI = false, its CSS scoped under.milkdown .ai-*).core, ctx, react, utils and preset-gfm are unchanged.
Regression
message-editor-teardown.browser.test.tsxruns in real Chromium with the realMessageEditor, Crepe and listener plugin:setTimeout,clearTimeoutandDateonly) from the first keystroke, so the publication is deterministically pending.destroyandmountedlistener events, never on time, then runs whatever was scheduled.MilkdownError: Context "editorView" not found(code: 'contextNotFound'). On 7.21.3 they pass and the sent text does not come back as a draft.No production source file changes, so nothing overlaps #3568's editor code. The immediate-send body snapshot and the undo and upload-failure attachment recovery keep their own suites.
Checklist
bun run checkpasses: not run locally (4 GiB sandbox); the focused gates below passed, and CI runs the full check.bun run lint:sastpasses: not run locally; left to CI's Opengrep job.Test plan
main(Milkdown 7.20.0): control passes, 2/3 fail with the reportedcontextNotFounderror.ConversationPanel/ComposeEmailPane, local fetch mocks, attachinvoice.pdf, typeUrgent, click Send message at once. Onmain: 2 unhandlededitorViewerrors (reply and compose). On this branch: 0. The payloads are unchanged; an immediate send onmainstill carriescontent: "", which is Bug: immediate Inbox Send can drop visible message text #3565 and fixed separately by fix(platform): send the live inbox editor document #3568.message-editor.browser.test.tsxplusconversation-header.browser.test.tsxplus the new file, 13/13 Chromium. The jsdom UI suites underapp/features/conversations, 26 files / 216 tests.oxlint --type-aware --type-checkandoxfmt --checkon the changed files;bun run lint:manualpasses. A coverage row was added totests/manual/reference/automation.md.mainin a separate worktree: 2 failed | 1 passed on 4 of 4 runs, always with thecontextNotFounderror.b44cc9288(local merges, clean, not pushed) = main842396aa2(which includes fix(platform): preserve Inbox drafts after upload failures #3566 as80759c7af) + fix(platform): send the live inbox editor document #356838e500b5d+ this PR0db69bf3c.message-editor-snapshot, fix(platform): preserve Inbox drafts after upload failures #3566'sinbox-upload-failure,message-editor,conversation-header, this regression and the Bug: Inbox editor emits an uncaught Milkdown error after rapid send #3567 probe.<p>Urgent</p>in all 4 payloads (immediate and delayed sends, reply and compose). This closes the gap fix(platform): send the live inbox editor document #3568 left open: all 4 payloads passed there, but 2 uncaught errors remained.app/features/conversations: 26 files / 215 tests pass.59bc6515c= main842396aa2+ this PR. Chromium 5 files / 30 tests, 0 unhandled errors; jsdom 26 files / 215 tests. Earlier checks also passed:de2fae080(mainbd5c2e71c+ fix(platform): preserve Inbox drafts after upload failures #3566cdb56c228+ this PR) and a pairwise cherry-pick onto fix(platform): send the live inbox editor document #3568's old head5e18078bd.0db69bf3c: 51 checks pass, 0 fail (8 skipped by design: fork-PR, release and container variants). The platformtest:browser,test:ui,typecheckandlintexecuted (cache miss), and the Browser job ranmessage-editor-teardown.browser.test.tsx(3 tests).