Skip to content

Commit 3be3f0f

Browse files
fix(FileUpload): revert to not calling onChange on file remove (#2521)
* fix: revert to not calling onChange on file remove * Create moody-coats-clean.md
1 parent 957049c commit 3be3f0f

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

.changeset/moody-coats-clean.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
"@razorpay/blade": patch
3+
---
4+
5+
fix(FileUpload): revert to not calling onChange on file remove
6+
7+
> [!NOTE]
8+
>
9+
> Check the below timeline if you're upgrading from 11.34.1+ version to this version
10+
11+
**Timeline of FileUpload changes**
12+
13+
- In 11.34.1: We did not call onChange on removing of file. Only onRemove was called
14+
- In 11:36.2: We added dispatchEvent call which started calling onChange on onRemove (since React treats `input type="file"` differently than `input type="text"` - [CodeSandbox Link](https://codesandbox.io/p/sandbox/friendly-ishizaka-yk7mm3))
15+
- In 12.4.0: We released a fix thinking onChange call was expected behaviour and we just updated the state value for it
16+
- **This version:** Reverts back to 11.34.1 behaviour. If you're upgrading to this version from 11.34.1 or previous versions, the behaviour will stay same. If you're upgrading from 11.34.1+ and use FileUpload component, its recommended to test out FileUpload instances.
17+
18+

packages/blade/src/components/FileUpload/FileUpload.web.tsx

+3-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { useState, useCallback, useMemo, useRef, forwardRef } from 'react';
2-
import { flushSync } from 'react-dom';
32
import type { FileUploadProps, BladeFile, BladeFileList } from './types';
43
import { StyledFileUploadWrapper } from './StyledFileUploadWrapper';
54
import {
@@ -29,7 +28,6 @@ import { useMergeRefs } from '~utils/useMergeRefs';
2928
import { useControllableState } from '~utils/useControllable';
3029
import { getInnerMotionRef, getOuterMotionRef } from '~utils/getMotionRefs';
3130
import { makeAnalyticsAttribute } from '~utils/makeAnalyticsAttribute';
32-
import { fireNativeEvent } from '~utils/fireNativeEvent';
3331

3432
const _FileUpload: React.ForwardRefRenderFunction<BladeElementRef, FileUploadProps> = (
3533
{
@@ -163,7 +161,6 @@ const _FileUpload: React.ForwardRefRenderFunction<BladeElementRef, FileUploadPro
163161
if (!hasValidationErrors) {
164162
handleFilesChange(droppedFiles);
165163
onDrop?.({ name, fileList: allFiles });
166-
fireNativeEvent(inputRef, ['change', 'input']);
167164
}
168165
};
169166

@@ -313,11 +310,9 @@ const _FileUpload: React.ForwardRefRenderFunction<BladeElementRef, FileUploadPro
313310
size={size}
314311
onRemove={() => {
315312
const newFiles = selectedFiles.filter(({ id }) => id !== selectedFiles[0].id);
316-
flushSync(() => {
317-
setSelectedFiles(() => newFiles);
318-
});
313+
setSelectedFiles(() => newFiles);
314+
319315
onRemove?.({ file: selectedFiles[0] });
320-
fireNativeEvent(inputRef, ['change', 'input']);
321316
}}
322317
onReupload={() => {
323318
const newFiles = selectedFiles.filter(({ id }) => id !== selectedFiles[0].id);
@@ -377,11 +372,8 @@ const _FileUpload: React.ForwardRefRenderFunction<BladeElementRef, FileUploadPro
377372
size={size}
378373
onRemove={() => {
379374
const newFiles = selectedFiles.filter(({ id }) => id !== file.id);
380-
flushSync(() => {
381-
setSelectedFiles(() => newFiles);
382-
});
375+
setSelectedFiles(() => newFiles);
383376
onRemove?.({ file });
384-
fireNativeEvent(inputRef, ['change', 'input']);
385377
}}
386378
onReupload={() => {
387379
const newFiles = selectedFiles.filter(({ id }) => id !== file.id);
@@ -400,7 +392,6 @@ const _FileUpload: React.ForwardRefRenderFunction<BladeElementRef, FileUploadPro
400392
const newFiles = selectedFiles.filter(({ id }) => id !== file.id);
401393
setSelectedFiles(() => newFiles);
402394
onDismiss?.({ file });
403-
fireNativeEvent(inputRef, ['change', 'input']);
404395
}}
405396
onPreview={onPreview}
406397
/>

0 commit comments

Comments
 (0)