diff --git a/src/components/inputs/upload-input-v4/__tests__/upload-input-v4.test.js b/src/components/inputs/upload-input-v4/__tests__/upload-input-v4.test.js
index 7f6de3f0..793a018a 100644
--- a/src/components/inputs/upload-input-v4/__tests__/upload-input-v4.test.js
+++ b/src/components/inputs/upload-input-v4/__tests__/upload-input-v4.test.js
@@ -324,10 +324,24 @@ describe('UploadInputV4', () => {
expect(await screen.findByText('File type not allowed')).toBeInTheDocument();
expect(screen.getByText('video.png')).toBeInTheDocument();
expect(screen.queryByText(/Uploading/)).not.toBeInTheDocument();
- expect(onError).toHaveBeenCalledWith(expect.any(Error), 412, 'test-upload');
+ expect(onError).toHaveBeenCalledWith(expect.any(Error), 412, 'test-upload', expect.any(File));
expect(api.puts()).toHaveLength(0);
});
+ test('onError passes the File that failed, not a sibling still uploading', async () => {
+ api.respond('PUT', /bucket\.test\/.*bad\.png/, () => api.networkError());
+ holdPuts();
+ const onError = jest.fn();
+ const { container } = render();
+ const good = fileOf('good.png', 2048, 'image/png');
+ const bad = fileOf('bad.png', 2048, 'image/png');
+ select(container, good, bad);
+
+ await screen.findByTitle('Retry');
+ expect(onError).toHaveBeenCalledTimes(1);
+ expect(onError.mock.calls[0][3]).toBe(bad);
+ });
+
test('a connection failure during the PUT shows the readable network message', async () => {
api.respond('PUT', /bucket\.test/, () => api.networkError());
const { container } = render();
@@ -376,6 +390,30 @@ describe('UploadInputV4', () => {
await waitFor(() => expect(api.calls('DELETE', /.*/).map(r => r.path)).toEqual(['/uploads/t1']));
});
+ test('dismissing an error row calls onRemove with the File that failed', async () => {
+ api.respond('PUT', /bucket\.test/, () => api.networkError());
+ const onRemove = jest.fn();
+ const { container } = render();
+ const file = fileOf('video.png', 2048, 'image/png');
+ select(container, file);
+ await screen.findByTitle('Retry');
+
+ act(() => { fireEvent.click(screen.getByRole('button', { name: 'Dismiss video.png' })); });
+
+ expect(onRemove).toHaveBeenCalledTimes(1);
+ expect(onRemove.mock.calls[0][0]).toBe(file);
+ });
+
+ test('dismissing a row rejected before upload does not call onRemove', async () => {
+ const onRemove = jest.fn();
+ const { container } = render();
+ select(container, fileOf('tool.exe', 2048, 'application/octet-stream'));
+
+ act(() => { fireEvent.click(screen.getByRole('button', { name: 'Dismiss tool.exe' })); });
+
+ expect(onRemove).not.toHaveBeenCalled();
+ });
+
test('retry uploads a failed file again and delivers it', async () => {
api.respond('PUT', /bucket\.test/, () => api.networkError(), { times: 1 });
const onUploadComplete = jest.fn();
diff --git a/src/components/inputs/upload-input-v4/index.js b/src/components/inputs/upload-input-v4/index.js
index 44b53d0c..ecf8c57a 100644
--- a/src/components/inputs/upload-input-v4/index.js
+++ b/src/components/inputs/upload-input-v4/index.js
@@ -87,6 +87,11 @@ const resolveErrorMessage = (err) => {
* (`${FILE_UPLOAD_API_BASE_URL}/api/v1/files`). Dropzone's `timeOut`,
* `parallelChunkUploads` and `maxConcurrentChunks` are accepted and ignored: Uppy
* retries each request on its own and limits concurrency across all files.
+ *
+ * Every File reported through `onUploadStart` is later reported once through
+ * `onUploadComplete`, `onError(err, status, id, file)` or `onRemove(file)`, and a
+ * retry starts it again. Dismissing its error row calls `onRemove`, so a parent can
+ * track exactly which files are running or failed.
*/
const UploadInputV4 = ({
value = [],
@@ -221,7 +226,8 @@ const UploadInputV4 = ({
{ id: file.id, name: file.name, size: file.size, message: resolveErrorMessage(err) },
]);
const { onError: callback, id: inputId } = propsRef.current;
- if (callback) callback(err, err?.status, inputId);
+ // the File reported by onUploadStart, so a parent can tell which upload failed
+ if (callback) callback(err, err?.status, inputId, file.data);
};
const onFileRemoved = (file) => {
// A delivered row stays until the parent confirms it through `value`.
@@ -322,10 +328,15 @@ const UploadInputV4 = ({
if (onRemove) onRemove(uppyFile?.data ?? { name: file.name, size: file.size });
}, [uppy, dropUploadingRow, onRemove]);
+ // A row rejected before Uppy took the file never reported onUploadStart, so it
+ // reports nothing here either.
const handleDismissError = useCallback((file) => {
setErrorFiles(prev => prev.filter(f => f.id !== file.id));
- if (uppy?.getFile(file.id)) uppy.removeFile(file.id);
- }, [uppy]);
+ const uppyFile = uppy?.getFile(file.id);
+ if (!uppyFile) return;
+ uppy.removeFile(file.id);
+ if (onRemove) onRemove(uppyFile.data);
+ }, [uppy, onRemove]);
const handleRetryError = useCallback((file) => {
setErrorFiles(prev => prev.filter(f => f.id !== file.id));