Repository navigation
feat(image): add upload progress, retry, and safe dialog lifecycle - #997
Conversation
Reuse the fixture-only hunk from f867088 (mdx-editor#996). Keep all existing Markdown, image, and focus assertions.
petyosi
left a comment
There was a problem hiding this comment.
Thanks for this. The lifecycle guards fix real bugs:
- A double submit uploads twice.
- A late upload still inserts after Cancel, Escape or a switch to read-only.
- The image lands in the wrong table cell.
- The image is inserted into a document that
setMarkdownhas replaced. - A failed upload is an unhandled rejection.
The label id fix is good too. A few things before it can go in:
1. insertImage$ keeps the unguarded path. The public signal still uses .then(handler) and reads activeEditor$ when the upload resolves, so the same stale-insert bug remains for imperative callers. Please send it through the same session/isCurrent guard.
2. Closing the dialog on every setMarkdown. The new link closes an open dialog on any non-whitespace markdown change, even when no upload is running. A parent that re-syncs non-normalized markdown on every change would close the dialog while the user types a URL. Please limit this to invalidating a pending upload, or explain why the dialog must close.
3. Dropping the upload when the active editor changes. This conflicts with 72b0140, where paste and drop uploads finish in the editor they started in. The dialog should behave the same way: capture the target editor when the dialog opens and insert there.
Smaller things
- Upload errors no longer reach the console. Please keep a
console.error, so failures can still be diagnosed when a custom dialog ignoresimageUploadState$. - Please drop the
table-image-dialog.spec.tshunk. That fixture is on main now.
The progress element and retry text are fine in the default dialog, because imageUploadState$ lets custom dialogs render their own.
Integrate current main without rewriting branch history. Guard imperative insertion, capture dialog targets at open, preserve idle URL dialogs on document resync, and retain upload diagnostics.
|
Updated this in
The focused integration suites passed 73 tests; the full suite passed 296 (1 existing skip, 1 todo), with lint/typecheck/build and independent review passing. Exact-head CI passed Test, Build JS and Build Docs, including packed React 18/19 consumers and cross-version replay. Browser validation remains incomplete: installation was cancelled before the browser test step, which was skipped. This supersedes the earlier pending CI status in the description. Target-switch coverage is from the integration tests, not a new browser pass. |
petyosi
left a comment
There was a problem hiding this comment.
Thanks for the update. Sharing one guard between insertImage$ and the dialog, keeping idle dialogs open on setMarkdown, and capturing the target editor are the right direction. A few regressions came with it:
1. Imperative uploads are tied to the dialog. insertImage$ attaches its request to any open dialog (image/index.ts:294), and every dialog state change deletes those requests (:224-227). Repro: openNewImageDialog$, then insertImage$({ file }), then closeImageDialog$, then the upload resolves. Main inserts the image. This PR drops it silently, and image-upload-lifecycle.test.tsx:552 asserts the drop. An imperative upload should not depend on dialog state. Please pass null there and invert that test.
2. Synchronous { src } inserts now go through the upload guard. startRequest needs a connected root, so a plugin that publishes insertImage$({ src }) in postInit (editor exists, root not attached yet) now loses the image with no error. Main inserted it. The same guard also turns insertImage$ into a no-op in read-only editors, and saveImage$ into a no-op when no dialog is open (:325). Main handled both. Please apply the lifetime guard only to asynchronous file uploads and keep { src } inserts as they were.
3. A dialog whose target editor is gone breaks without feedback.
- Open the dialog in a table cell, submit an upload, remove the table, then let the upload resolve.
saveonly callsfinish()(:297), so the state staysuploading. The fields and Save stay disabled, and only Cancel works. - Open an idle dialog in a table cell, enter a URL, call
setMarkdown, then press Save.startRequestreturns undefined (:325-327). The dialog stays open, nothing is inserted, and nothing is logged.
While the dialog session is current but its target no longer exists, please close the dialog or publish an error state. Never return silently.
Smaller things
- A custom dialog that publishes
saveImage$and closes right away now loses the upload. That follows from "Cancel discards", but please document it for custom dialogs. - The
setMarkdown$filter (:238) repeats core's trim check and ignoresviewMode$. - Dialog session identity depends on
map(() => ({ type: 'new' }))producing a fresh object (:457). A comment would help, or replace it with a counter. One document-generation counter, bumped onsetMarkdown, read-only and dispose, could also replace therequestsset,dialogRequestanddisposed, and would fix (1) by design. - The browser job was cancelled, so
image-upload-lifecycle.spec.tshas never run. Please get it green.
…rgets Separate asynchronous file lifetime guards from synchronous URL insertion. Keep imperative file uploads independent of dialog sessions, close stale-target dialogs, match source-mode document replacement semantics, and document custom dialog cancellation. Add regressions for the reviewed public API contracts.
|
Thanks for the detailed review. Addressed in d4105b8 and 794068c:
Validation for exact head |
|
Merged, thanks. All three points are fixed:
The On top of it, 0d0cfba fixes one case the session tokens made easy to reach. If |
|
🎉 This PR is included in version 4.5.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Closes #268.
Implementation
insertImage$uploads. Imperative uploads capture their target at invocation; dialogs capture theirs when opened. Focus/editor changes do not cancel an otherwise valid upload or redirect its result.setMarkdownresync leaves an idle URL dialog and its fields intact.console.error, including custom dialogs, without exposing raw errors in the default UI.The callback remains
File => Promise<string>; invalidation does not abort its network request. Paste/drop behavior is unchanged. Custom dialogs can readimageUploadState$(idle,uploading,error).Verification
Head:
1972c6dd5189634b425e0947f4777366a9899d16. Published tree14d21dc33f24ff3026b545475fae4ca1f64517b3matches the tested local tree exactly.Exact-head CI run 40539763308: Test and Build Docs have passed; Build JS and Browser compatibility are still running. No browser/package/cross-version pass is claimed yet.
Maintainer re-review remains pending; successful tests do not constitute acceptance or merge.