Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions shesha-reactjs/src/providers/storedFile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,28 +140,34 @@

useEffect(() => {
if (uploadMode === 'sync' && value) {
const fileInfo: IStoredFile = value
? {
// id: value.uid,
const isFileObject = value instanceof File || (value?.uid && value?.name && value?.size);

if (isFileObject) {
const fileInfo: IStoredFile = {
uid: value.uid,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Critical: uid will be undefined for File instances.

When value is a File instance, value.uid will be undefined because the native File API does not include a uid property. Since IStoredFile extends UploadFile (from antd), the uid is typically required for tracking files in the upload component. This will likely cause runtime issues with file display and tracking.

Generate a unique uid for File instances:

       if (isFileObject) {
         const fileInfo: IStoredFile = {
-          uid: value.uid,
+          uid: value.uid || `sync-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
           url: null,
           status: 'done',
           name: value.name,
           size: value.size,
           type: value.type,
           originFileObj: null,
         };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
uid: value.uid,
uid: value.uid || `sync-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
🤖 Prompt for AI Agents
In shesha-reactjs/src/providers/storedFile/index.tsx around line 147, the code
assigns uid: value.uid which will be undefined for native File instances; detect
when value.uid is falsy and generate a stable unique uid (for example
Date.now().toString() + Math.random() or a UUID) and assign that uid to the
IStoredFile object so UploadFile consumers always have a valid uid; ensure the
generated uid is a string and used consistently for tracking/display in the
Upload component.

url: null,
status: 'done',
name: value.name,
size: value.size,
type: value.type,
originFileObj: null,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

originFileObj should reference the actual File object.

When value is a File instance, originFileObj should preserve a reference to it rather than being set to null. This property is used by upload components to access the original file data.

-          originFileObj: null,
+          originFileObj: value instanceof File ? value : null,
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
originFileObj: null,
originFileObj: value instanceof File ? value : null,
🤖 Prompt for AI Agents
In shesha-reactjs/src/providers/storedFile/index.tsx around line 153,
originFileObj is being set to null but should reference the actual File when
value is a File instance; change the assignment so that originFileObj = value
when value instanceof File (otherwise keep null) so upload components can access
the original File object.

}
: null;
};
dispatch(fetchFileInfoSuccessAction(fileInfo));
} else {

Check failure on line 156 in shesha-reactjs/src/providers/storedFile/index.tsx

View workflow job for this annotation

GitHub Actions / build-attempt

Block must not be padded by blank lines

dispatch(fetchFileInfoSuccessAction(fileInfo));
if (newFileId) {
fileFetcher.refetch({ queryParams: { id: newFileId } });
}
}
}
if (uploadMode === 'sync' && !Boolean(value)) {
dispatch(deleteFileSuccessAction());
}
}, [uploadMode, value]);

useEffect(() => {
if (!isFetchingFileInfo && uploadMode === 'async') {
// Process fetch responses for async mode OR when we manually fetched in sync mode for existing files
if (!isFetchingFileInfo) {
if (isAjaxSuccessResponse(fetchingFileInfoResponse)) {
const fetchedFile = fetchingFileInfoResponse.result;
if (fetchedFile) {
Expand Down
Loading