Repository navigation
fix(admin-ui): show an uploading state while any upload collection saves a file - #892
Conversation
…ves a file Saving a document with a file attached gave no feedback between submit and the response: the button faded and nothing else changed, so a large file on a slow connection read as a frozen page. An admin reported being unable to get past the meditation upload screen, and that silent wait was the whole cause. Payload publishes the state and renders nothing for it. `Form` holds `processing` and exposes it through `useFormProcessing()`; `<Upload>` reads the same hook only to reset its remove-file state, and none of the 33 `upload` options covers progress. So the notice is ours to render. `UploadNotice` shows a `Spinner` while `useFormProcessing()` is true AND form state's `file` path holds a `File`. Neither half alone is the signal: processing is equally true of a save posting no file, and `data-form-ready` is also false while the form initializes. `uploadNoticePlugin` wires it for every collection with `upload` set, because per-collection wiring is the step someone forgets — the coverage criterion is what the ticket actually asks for. A collection naming its own Upload component is skipped and composes the notice itself; overriding `AudioUpload` would have cost the audio player and the frame-drift banner. `<Upload>`'s own `UploadControls` slot cannot carry this. It renders inside the dropzone, and the dropzone gives way to the staged-file preview the moment a file is chosen — so the slot is empty exactly when the notice is needed. Both specs were watched failing before they were kept. The registration assertions needed a second pass: searching the whole file let the import stand in for the registration, and comparing raw `indexOf` results let `-1` pass the ordering check, so deleting the registration left them green twice over. Refs #888 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KQVFrCyfkChD53QyPK3dsJ
…hows an empty box Payload hands a replacement Upload component no props at all — it reads the node off `useDocumentInfo().Upload` and renders it bare — so everything its own two call sites pass has to be re-sourced. `initialState` was missing from both this PR's new component and the existing `AudioUpload`. It is optional, so omitting it compiles and looks correct on the edit view. `<Upload>` sets `fileSrc` from it on mount and gates the whole staged-file block — thumbnail, filename input, remove button, crop — on `value && fileSrc`. A click sets `fileSrc` itself, so only a form arriving with a `File` already staged needs it: the Bulk Upload drawer, which renders one pre-staged form per file. Without it that drawer showed an empty box. That was already true for Songs through `AudioUpload`, and this PR's plugin would have extended it to the six collections it newly wires. One cause, one fix, both call sites. `UploadControls` and `customActions` reach those call sites as props and sit on no context, so they cannot be re-sourced. Recorded as a limitation rather than worked around — no collection here configures either. The forwarding is spec'd, because nothing else can see it: the prop is optional, the staged-file block belongs to `@payloadcms/ui`, and no pure test reaches the wiring. Watched failing with the prop removed. Refs #888 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KQVFrCyfkChD53QyPK3dsJ
…oad slot The notice was wired as `admin.components.edit.Upload`, which *replaces* Payload's upload box. Every awkward part of the first two commits came from that one choice, and `edit.beforeDocumentControls` removes all of it: a `CustomComponent[]`, rendered unconditionally as the first child of the controls row, inside the `<Form>` the notice reads. Because it is an array the plugin appends, so nothing can collide. That drops the skip branch for collections with their own Upload component — which also meant every future custom-Upload collection opted out of this fix silently, and that `AudioUpload` returning null during live preview took the notice with it. It also drops `UploadWithNotice` and its spec, 161 lines whose only job was re-implementing Payload's own call site faithfully: a replacement component receives no props, so `initialState` had to be re-sourced, and `UploadControls` and `customActions` could not be re-sourced at all. The one thing the Upload slot covered and this does not is the Bulk Upload drawer, and that coverage was inert. `FormsManager.saveAllDocs` builds each request itself and `fetch`es in a loop, never calling the nested form's submit, so `useFormProcessing()` stays false there and the notice could never have fired. The drawer already renders its own `LoadingOverlay` with a `general:uploadingBulk` progress count, which is better than ours. `AudioUpload` keeps one line from the reverted work: forwarding `initialState`. That bug is older than this branch and independent of the notice — without it the Songs bulk drawer renders an empty box, since `<Upload>` sets `fileSrc` from `initialState` and gates the staged-file block on it. Also folded in: the coverage spec now reuses `SRC`/`sourceOf` from `tests/utils/importGraph` instead of a second cwd-dependent definition, both specs import the component directly rather than copying a dynamic-import dance that only its precedent's module state needed, and the story lives in `docs/rules/admin-ui.md` once instead of four times. The new assertions were watched failing: skipping a collection, and replacing the slot's existing contents instead of appending. Refs #888 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KQVFrCyfkChD53QyPK3dsJ
…d it Payload renders no feedback for a multipart save, so the notice is ours. The part worth writing down is which slot to mount such a thing in: an additive `CustomComponent[]` rather than a replacement, and the three costs of the replacement slot — a skip branch, a component that must re-source every prop Payload passes at its own call sites (and cannot re-source two of them), and bulk-drawer coverage that never fires because `saveAllDocs` bypasses the form. Each is invisible from the call site and each cost this branch a revision. Refs #888 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KQVFrCyfkChD53QyPK3dsJ
|
🚅 Deployed to the SahajCloud-pr-892 environment in sahajcloud
1 service not affected by this PR
|
|
🤖 no session running recent dispatchesWritten by the sydevs dispatcher. Sessions never edit this comment. |
sydevs-bot
left a comment
There was a problem hiding this comment.
🧐 Adversarial review
Holistic. The code half is as small as the problem: 33 source lines cover all 8 upload collections, with no schema and no contract surface. The additive-slot choice is right, and I verified both Payload claims it rests on. The prose half is not: 58 comment and doc lines for those 33, and the rejected edit.Upload design is explained four times over. Nothing else in the diff exceeds the ticket.
Findings
should-fix—docs/rules/admin-ui.md:44: the rules doc post-mortems an approach the codebase does not contain. Three other files repeat it.consider—UploadNotice.tsx:22: the notice is the only untranslated string on a row of translated controls.
What was checked
Ticket #888 and its five acceptance criteria, the diff whole, plus these reads in Payload 3.90.2:
DocumentControls/index.js:222renders the slot first inside__controlsand callsuseFormProcessing()itself. The notice is inside<Form>, as claimed.Upload/index.js:177writes the stagedFileto form statefile. The predicate holds.FormsManager/index.js:296builds FormData and fetches in a loop, never submitting the nested form. The claim that reversed the design is true, and:314confirms the drawer's own translated overlay.Upload/index.js:300,448gate the staged-file block onvalue && fileSrc, set frominitialState. TheAudioUploadfix is real.- No
pasteURLinsrc/, so no server-fetch save slips the predicate. NextStepButtoncallsuseForm().submit(), so the notice fires on the reported Meditations path.- Folding this into
storagePluginwould lose the no-wiring criterion. It keys off a hardcoded slug map, notcollection.upload. accessPlugincreates no collection, so registering before it costs nothing.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
The rule file loads on every `src/components/admin/**/*.tsx` read, so it pays for its length on every one. The skip-branch and inert-advantage bullets record a design this codebase does not contain, and the PR body already holds that record. The `initialState` trap stays: it is the one fact a future replacement-Upload author needs, and nothing but prose carries it. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_011y14iwdbWnNNbp3AwArBwJ
The notice sat in a row of translated controls as the one English string, and #888 was reported from a Czech panel. `general:uploading` is the key Payload's own bulk-upload overlay uses, so every locale the admin ships already carries it ("Nahrávání" in Czech). The cost is the "please keep this page open" half of the sentence: carrying that would need a custom translation catalogue, which this repo has no precedent for. The spinner still says a wait is in progress. The spec's stubbed `t` answers a Czech string, so a hardcoded English label fails the assertion instead of passing it. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_011y14iwdbWnNNbp3AwArBwJ
|
Both adversarial-review threads adopted. Pushed
Dropped with that sentence: "please keep this page open". A custom translation catalogue is the only way back, and this repo has no precedent for one. Say so and I will add it. Lean gate green — lint, typecheck, typecheck:tests, 2288 unit. No integration re-run: neither commit touches the sanitized config. The label assertion was watched failing against a hardcoded English string. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
The seven-line JSDoc paragraph re-derived a mechanism docs/rules/admin-ui.md already owns in full, naming AudioUpload as it does. What a reader of this file needs is the constraint and its silent failure, so that is what stays, with the rule as the breadcrumb. The ⚠ marker stays per docs/rules/code-comments.md. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012CgfQaLhixYAnwH3yk8W1u
|
Both review threads answered. Pushed
Lean gate green: lint, typecheck, typecheck:tests, 2291 unit. No integration re-run — the commit changes a comment only, and nothing in the sanitized config. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
Two plugins did one job. The notice is about an upload, so it belongs with the plugin that owns uploads, and uploadNoticePlugin's only reason to exist separately was that storagePlugin returns early when disabled and again when any Cloudflare credential is missing. Applying the transform above both returns removes that reason. A save still posts a file on all three paths — local dev, the test suite, migrate:create — and the notice now mounts on each of them, which the standalone plugin also did and a fold below the returns would not. It stays keyed on collection.upload rather than STORAGE_BACKENDS, so a new upload collection is still covered before anyone picks its backend. The component path is unchanged, so the generated import map is untouched — generate:importmap finds no new imports, which is what proves the registration is still live. Both regressions the fold invites were watched failing: the notice applied below one early return, and the notice keyed off the backend map. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VnoZhXSpH8pMvfkW5HAemh
|
Review thread adopted. Pushed
The fold moves the notice from second-to-last in Lean gate green: lint, typecheck, typecheck:tests, 2293 unit. Both regressions the fold invites were watched failing: the transform below one early return, and the notice keyed off the backend map. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
Summary
Spinnernow shows from submit until the response whenever a save posts a file, on all 8 upload collections.storagePlugin, in an additive slot — a new upload collection gets it with no wiring, and none can opt out.Change outline
Flow — where the notice mounts, and what Payload gives it
Edit view @payloadcms/ui/views/Edit <Form> # holds `processing`, publishes via ProcessingContext BeforeFields → <Upload> # or edit.Upload, which REPLACES this <DocumentControls> + BeforeDocumentControls # edit.beforeDocumentControls, CustomComponent[] + UploadNotice # unconditional, inside <Form> + useFormProcessing() ∧ fields.file.value instanceof File + → <Spinner loadingText={t('general:uploading')} /> SaveDraftButton / PublishButtonBoth halves of the predicate are load-bearing.
processingis equally true of a save posting no file;data-form-readyis also false while the form initializes. The stagedFilesits at form state'sfilepath, where Payload's own<Upload>writes it throughuseField({ path: 'file' }).Behaviour — where the transform runs, and why that line
storagePlugin(options) src/plugins/storage/ (incomingConfig) => + withUploadNotice(withObjectKeyColumn(incomingConfig)) for each collection no `upload` → return the same object # untouched, no spread append UPLOAD_NOTICE to edit.beforeDocumentControls !enabled → return # E2E any Cloudflare credential missing → return # local dev, test suite, migrate:create cloudStoragePlugin({ … })(config)One plugin, not two. ⚠ The transform is applied above both early returns, which is the whole of why the fold is safe: a save still posts a file when the plugin is disabled and when the credentials are absent, and a notice folded in below either return would mount in none of those environments. It stays keyed on
collection.uploadrather thanSTORAGE_BACKENDS, so a new upload collection is covered before anyone picks its backend.beforeDocumentControlsis an additive array slot, so no collection is skipped and none loses what it declared.AudioUploadkeeps its ownedit.Uploadand gets the notice.Files
Preview
AudioUploadslot, which keeps its player and drift bannerinitialStatefixTest results
pnpm lint,pnpm typecheck,pnpm typecheck:tests,pnpm test:unit(2293 passed)tests/int/collections-smoke.int.spec.ts19 passed — the config canary, since the notice changes every upload collection's sanitized configtests/unit/upload-notice.spec.ts(4),tests/unit/upload-notice-coverage.spec.ts(6),tests/unit/upload-notice-storage.spec.ts(3)pnpm generate:importmapreports no new imports, which is what proves the component is still registered after the foldEvery new assertion was watched failing first: each half of the predicate removed in turn, the slot's existing contents replaced instead of appended, the label hardcoded in English, the notice applied below one of
storagePlugin's early returns, and the notice keyed offSTORAGE_BACKENDSinstead ofcollection.upload.Manual verification
Automated specs cover the predicate and the wiring. What they cannot reach is a real browser doing a real multipart POST:
AudioUpload. Confirm the audio player and the frame-drift banner still render.mainthis pane is empty (see below).The Images and Videos storage adapters have not been checked against this behaviour, per the ticket.
Notes for reviewer
The notice now lives in
storagePlugin, per review. The separate plugin's only reason to exist was thatstoragePluginreturns early when disabled and again when any Cloudflare credential is missing. Applying the transform above both returns removes that reason and keeps the coverage identical — the credentials now decide where a file goes, never whether the save says anything. Two specs hold that line, both watched failing:upload-notice-storage.spec.tsdrives the plugin through all three paths, and the backend-map keying regression failsupload-notice-coverage.spec.tsas well.The ticket's preferred approach does not work, and nor does its fallback's slot. It asked me to try
<Upload>'sUploadControlsslot first. That slot renders inside the dropzone, which the staged-file preview replaces the moment a file is chosen — so it is empty exactly when the notice is needed. The ticket's fallback was to wrap<Upload>viaedit.Upload; I built that, then moved off it.edit.Uploadreplaces Payload's upload box, which forces a skip branch forAudioUpload(so every future custom-Upload collection would opt out silently, andAudioUploadreturningnullduring live preview would take the notice with it) and forces a 50-line re-implementation of Payload's own call site.beforeDocumentControlsis additive and costs none of it. The history has both, so the diff is reviewable either way.The one thing
edit.Uploadcovered and this does not is the Bulk Upload drawer — and that coverage was inert.FormsManager.saveAllDocsbuilds each request itself andfetches in a loop, never calling the nested form's submit, souseFormProcessing()staysfalsethere and the notice could never have fired. The drawer already renders its ownLoadingOverlaywith ageneral:uploadingBulkprogress count, which is better than ours. Worth a sanity check — it is the one claim that reversed the design.An incidental pre-existing bug is fixed here:
AudioUploadnever forwardedinitialState, so the Songs bulk-upload drawer renders an empty box today. One line, and it is the same root cause this PR documents — a replacement Upload component receives no props, so everything Payload passes at its own call sites must be re-sourced. Meditations is unaffected (bulkUpload: false).Known limitation, recorded not worked around:
UploadControlsandcustomActionsreach the Edit view and the bulk drawer as props and sit on no context, so a collection with its ownedit.Uploadcomponent cannot re-source them. No collection here configures either.The label is Payload's
general:uploading, not our own sentence. It is the key the bulk drawer's own overlay uses, so every locale the admin ships already carries it — Czech reads "Nahrávání", and #888 was reported from a Czech panel. The cost is the "please keep this page open" half of the ticket's proposed wording: carrying that needs a custom translation catalogue, which this repo has no precedent for. Say so if you want one.Dismissed finding: a reviewer flagged that
AudioUploadshows no notice while live preview is open. It returnsnullthere wholesale, so there is no upload control to start a save from in that state — and the additive slot makes the question moot, since the notice is now a sibling of the Save button rather than a child ofAudioUpload.Detail
Why render it ourselves. Payload publishes the state and leaves the rendering to the app:
Formholdsprocessingand exposes it throughProcessingContextanddata-form-ready, while<Upload>reads the same hook only to reset itsremovedFilestate. None of the 33uploadoptions covers progress. Discussion payloadcms/payload#1180 asked for this and was closed asroadmap: completeby PR #1923, which covered lists, document load and lazy editors — never the multipart save.Built-in primitive used, per the "Prefer Payload's built-in components" rule:
Spinnerfrom@payloadcms/ui(spinner icon plusloadingText, themed, inline flex). Nothing was missing, so no custom-styled component was written.docs/rules/admin-ui.md's Loading row now names it.The fold moved the notice earlier in the
pluginsarray, from second-to-last to fourth. That costs nothing today: no plugin registered afterstoragePlugincreates an upload collection — checked across this repo's own plugins and the three@payloadcmsones in the list, where form-builder'suploadis a field-block option rather than a collection. A future plugin that creates one would need the notice applied after it, which is the one thing the old position bought.Fixture pre-mortem. The coverage spec asserts over the real
@/collectionsarray rather than a fixture, because a fixture would assume the very thing under test — which collections declareupload. Verified againstsrc/collections/index.tsand the eightupload:blocks (Files, Frames, Images, Meditations, SongTags, Songs, UserChoices, Videos). The synthetic collections in that spec cover only what the real array cannot show: a brand-new upload collection, and one already using the slot. The storage spec adds apodcastscollection that is deliberately not aSTORAGE_BACKENDSslug.Registration is now asserted by behaviour, not by text. The old spec sliced
payload.config.tsfor the plugin's name, because the alternative wasbuildConfig, which boots Payload.upload-notice-storage.spec.tsneeds neither: it callsstoragePlugindirectly with@/lib/envmocked — the shapestorage-object-key.spec.tsalready uses — so the assertions read the config the plugin actually returns. The generatedimportMap.jsentry is still asserted beside it, since that entry exists only becausegenerate:importmapresolved the component on the sanitized config.A vacuous-assertion trap, caught and fixed. The first version of the registration assertions searched the whole file and compared raw
indexOfresults, so deleting the registration left them green twice over — the import satisfiedtoContain, and-1 < nsatisfied the ordering. Those assertions are gone with the text slicing, but the lesson is why the replacement asserts the returned config rather than a source file.A measurement correction. An earlier draft of that spec's docblock claimed importing
@/collections"costs nothing". Measured: ~3.4s of import and transform against a 0.16s baseline. The marginal lane cost is nil (23 unit specs already pay for the graph, and adding this file moved a two-file run by 0.01s), so the conclusion stands, but the comment no longer reads as licence to add the import where it is not amortized.No migration. The notice touches
admin.componentsonly — no schema, no fields, no DB change.Rejected alternatives. A
uifield would also cover both views and has repo precedent (src/fields/previewTargetField.ts), but it joins the list-view column selector unless the plugin also setsadmin.disableListColumn, needs a name unique against each collection's fields, and lands wherever it is spliced in field order.beforeDocumentControlsis one line with none of that.beforeFieldsis not an option at all: the Edit view reads it offuseDocumentInfo()and falls back to the upload box itself, so supplying it would replace<Upload>.Closes #888
🤖 Generated with Claude Code
https://claude.ai/code/session_01KQVFrCyfkChD53QyPK3dsJ