Skip to content

Conversation

@James-Baloyi
Copy link
Contributor

@James-Baloyi James-Baloyi commented Nov 3, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Improved file synchronization so uploaded files and stored files are correctly distinguished, preventing incorrect file metadata display.
    • Non-file inputs no longer produce misleading immediate file info; existing stored files will be re-fetched when needed.
    • Fetch handling expanded so updates from both automatic and manual fetches are reliably applied.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 3, 2025

Walkthrough

In sync mode, value inputs are now type-checked: actual File objects (or objects with uid/name/size) are converted to full IStoredFile and dispatched; non-file values no longer immediately dispatch and instead trigger a fileFetcher.refetch when a newFileId exists. Async fetch response handling was broadened to run when not fetching.

Changes

Cohort / File(s) Summary
StoredFile provider
shesha-reactjs/src/providers/storedFile/index.tsx
Refined effect logic: added isFileObject check to build and dispatch IStoredFile for File-like values; removed immediate dispatch for non-file values and added conditional fileFetcher.refetch({ queryParams: { id: newFileId } }) when newFileId present; widened async-fetch handling to process responses whenever not fetching. Minor comment updates.

Sequence Diagram

sequenceDiagram
    participant E as Effect Hook
    participant V as value (prop)
    participant C as isFileObject check
    participant B as Build & Dispatch
    participant R as fileFetcher.refetch

    E->>V: value change
    E->>C: check File or uid/name/size?
    alt is file-like
        C->>B: build IStoredFile (uid,url,status,name,size,type,originFileObj)
        B->>E: dispatch fetchFileInfoSuccessAction
    else not file-like
        C->>R: if newFileId present
        alt newFileId present
            R->>R: refetch({ queryParams: { id: newFileId } })
        else no newFileId
            R-->>E: no action
        end
    end

    rect #f8f9fa
    Note over E,R: Async fetch responses now processed when not fetching (covers async mode and manual sync refetches)
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Pay attention to: isFileObject detection logic, dispatch points (removed/added), and the fileFetcher.refetch call site.
  • Verify that broadened async-response handling doesn't regress manual-sync or upload-mode behavior.

Suggested reviewers

  • AlexStepantsov

Poem

🐇 I hopped through hooks and files today,

Found true Files that wanted to stay.
Others I nudged to fetch once more,
So stored data lands safe on the shore.
— Thumper, the Code Rabbit 🐾

Pre-merge checks and finishing touches

✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title 'handle file upload async and sync render modes' directly aligns with the main changes in the pull request. The raw summary clearly shows that the modifications primarily address how file uploads are handled in both async and sync modes, including conditional logic for file objects, refetching behavior, and broadened fetch response processing. The title accurately captures this dual-mode handling as the core focus of the changeset.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 43f4c8c and 07c1410.

📒 Files selected for processing (1)
  • shesha-reactjs/src/providers/storedFile/index.tsx (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
shesha-reactjs/src/providers/storedFile/index.tsx (2)
shesha-reactjs/src/providers/storedFiles/contexts.ts (1)
  • IStoredFile (26-33)
shesha-reactjs/src/providers/storedFiles/actions.ts (1)
  • deleteFileSuccessAction (60-63)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build-attempt
🔇 Additional comments (1)
shesha-reactjs/src/providers/storedFile/index.tsx (1)

169-170: LGTM: Broadened fetch response handling.

The condition change from uploadMode === 'async' to !isFetchingFileInfo correctly enables processing of fetch responses for both async mode and manual sync-mode fetches (triggered at line 159). The updated comment clearly documents this behavior.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
shesha-reactjs/src/providers/storedFile/index.tsx (1)

146-154: Consider including id in the constructed IStoredFile for consistency.

The async mode (lines 174-182) includes the id property when constructing IStoredFile, but the sync mode omits it. If newFileId is available (which could be from value?.id), consider including it in the constructed object for consistency between modes.

       if (isFileObject) {
         const fileInfo: IStoredFile = {
+          id: newFileId || null,
           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,
+          originFileObj: value instanceof File ? value : null,
         };
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e31394f and 43f4c8c.

📒 Files selected for processing (1)
  • shesha-reactjs/src/providers/storedFile/index.tsx (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
shesha-reactjs/src/providers/storedFile/index.tsx (1)
shesha-reactjs/src/providers/storedFiles/contexts.ts (1)
  • IStoredFile (26-33)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build-attempt


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.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant