Upload media files sequentially instead of all at once (#432) - #433
Open
willdarbey123-netizen wants to merge 1 commit into
Open
Conversation
handleFiles is written as a sequential loop, but `await toast.promise()` does not wait for the upload: sonner's toast.promise() returns the toast id synchronously (with an `unwrap` helper attached), not the promise. So the loop moved on immediately and every file in a batch was in flight at the same time. Each upload is its own commit, and concurrent commits to the same branch race on the branch head. GitHub rejects all but one per round with "is at <sha> but expected <sha>", so a multi-file upload landed some files and failed the rest. Await the upload promise itself. A failed file is already reported by the toast, so the loop carries on with the remaining files rather than aborting the batch. Fixes hunvreus#432 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #432.
Problem
Selecting several files at once in a media library (multi-select, or dropping a selection on the drop zone) uploads them concurrently. Each upload is a commit, so the requests race on the branch head and GitHub rejects all but one per round:
Some files in the batch land, the rest fail, and it gets worse the more files are selected. One file at a time works.
Cause
handleFilesincomponents/media/media-upload.tsxis written as a sequential loop, but it awaits the wrong thing:sonner's
toast.promise()(^2.0.7) returns the toast id synchronously, with anunwraphelper attached, not the promise:So the
awaitresolves immediately, and becauseuploadPromiseis an IIFE that has already started itsfetch, every file in the batch is in flight together.Change
Keep
toast.promise()for the notification, and await the upload itself. A failed file is already reported by the toast, so the loop continues with the remaining files rather than aborting the batch.One hunk, one file. The rich-text image insert path (
components/ui/editor/index.tsx) already awaitsonUploadImagedirectly and is unaffected.components/folder-create.tsx:89uses the sameawait toast.promise(...)pattern but as a single call, not a loop, so it is left alone here.Testing
Not run against a local instance (PostgreSQL + GitHub App). The change is a direct
awaiton the existing promise, and the failure was reproduced repeatedly on app.pagescms.org with 5 to 30 files selected, matching the analysis above. Happy to adjust if you'd preferawait toast.promise(...).unwrap()instead.🤖 Generated with Claude Code