Skip to content

fix(platform): cancel pending Inbox editor work on teardown - #3578

Merged
yannickmonney merged 1 commit into
mainfrom
fix/inbox-editor-teardown-pending-publication
Sep 28, 2026
Merged

yannickmonney merged 1 commit into
mainfrom
fix/inbox-editor-teardown-pending-publication

Conversation

@yannickmonney

@yannickmonney yannickmonney commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

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/kit and @milkdown/react to 7.21.3 and adds a real-editor teardown regression.

Closes #3567

Root cause

  • MessageEditor remounts its MilkdownProvider after a successful send, and the panel keys it by conversation. @milkdown/react then calls editor.destroy(), and the editor-view plugin's cleanup runs view.destroy() followed by ctx.remove(editorViewCtx).
  • @milkdown/plugin-listener 7.20.0 schedules debouncedHandler (a lodash debounce, 200 ms) on every document-changing transaction. Its ProseMirror plugin view's destroy only notified destroy listeners; it did not cancel the debounce (src/index.ts L165–194).
  • When the timer fires, serializer(doc) reaches the commonmark paragraph toMarkdown runner. That runner calls ctx.get(editorViewCtx), which throws contextNotFound uncaught inside the timer.
  • 7.21.2 and later call debouncedHandler.cancel() in that destroy (upstream a1868c02a7).

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-diff and @milkdown/plugin-streaming. katex stays on the root 0.16.47 override; crepe calls only katex.render and renderToString. Milkdown's only consumer is message-editor.tsx.

  • Upstream changes from 7.20.0 to 7.21.3, reviewed from source:

    • the listener cancel;
    • link href sanitizing in toDOM, which also covers getHTML(), plus an SVG-aware Mermaid sanitizer and rel="noopener noreferrer" on link previews;
    • the Markdown serializer keeps a mark open across adjacent text nodes (a fidelity fix; plain text is unchanged);
    • lifecycle guards (list-item rAF after destroy, the latex tooltip on read-only editors);
    • an opt-in AI feature (defaultFeatures.AI = false, its CSS scoped under .milkdown .ai-*).

    core, ctx, react, utils and preset-gfm are unchanged.

Regression

message-editor-teardown.browser.test.tsx runs in real Chromium with the real MessageEditor, Crepe and listener plugin:

  • The clock is fake (setTimeout, clearTimeout and Date only) from the first keystroke, so the publication is deterministically pending.
  • Teardown comes from a real send (remount) or from leaving (unmount). The test waits on Milkdown's own destroy and mounted listener events, never on time, then runs whatever was scheduled.
  • A control proves the same clock hands a live editor's edit to the persisted draft, so the teardown cases cannot pass vacuously.
  • On 7.20.0 both teardown cases fail with 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 check passes: not run locally (4 GiB sandbox); the focused gates below passed, and CI runs the full check.
  • bun run lint:sast passes: not run locally; left to CI's Opengrep job.
  • Translations: N/A, no user-visible string changed.
  • Docs: N/A, the only user-visible change is that an uncaught console error goes away.
  • README: N/A.

Test plan

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
yannickmonney merged commit be02b16 into main Sep 28, 2026
59 checks passed
@yannickmonney
yannickmonney deleted the fix/inbox-editor-teardown-pending-publication branch September 28, 2026 08:27

@yannickmonney yannickmonney left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant