Skip to content

fix(file-upload): Fix bug in file-upload component where multiple selections are merge-service and uploaded #3424

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 16, 2025

Conversation

chenxi-20
Copy link
Collaborator

@chenxi-20 chenxi-20 commented May 14, 2025

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features

    • Improved file upload validation to support merged uploads by individually validating each file in a batch and removing unsupported files before upload.
  • Bug Fixes

    • Enhanced accept type checking to ensure only valid files are uploaded, especially when uploading multiple files at once.

@chenxi-20 chenxi-20 added the bug Something isn't working label May 14, 2025
Copy link

coderabbitai bot commented May 14, 2025

Walkthrough

A helper function isAcceptType was added to check if files match accepted types, including special handling for image types. The beforeUpload function now accepts an additional isMergeUpload parameter to validate and filter multiple files during merged uploads. The handleStart logic was updated to pass this new parameter.

Changes

File(s) Change Summary
packages/renderless/src/file-upload/index.ts Added isAcceptType helper; updated beforeUpload signature and logic to support merged uploads by filtering files; modified handleStart to pass isMergeUpload parameter.

Poem

A helper hops in, checks file type with care,
Filtering uploads, making sure they're fair.
Merged files now sorted, only the best survive,
With a new parameter, uploads truly thrive!
🐰✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/renderless/src/file-upload/index.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-vue".

(The package "eslint-plugin-vue" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-vue@latest --save-dev

The plugin "eslint-plugin-vue" was referenced from the config file in ".eslintrc.js » @antfu/eslint-config » @antfu/eslint-config-vue".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.


📜 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 3f7b9a7 and fe7ea25.

📒 Files selected for processing (1)
  • packages/renderless/src/file-upload/index.ts (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/renderless/src/file-upload/index.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: PR E2E Test (pnpm test:e2e3)
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@chenxi-20 chenxi-20 changed the title fix(file-upload): Fix bug in file upload component where multiple selections are merged and uploaded fix(file-upload): Fix bug in file upload component where multiple selections are merge-service and uploaded May 14, 2025
Copy link

Walkthrough

This PR addresses a bug in the file upload component where multiple file selections were incorrectly merged and uploaded as a single file. The changes introduce a mechanism to handle multiple file uploads correctly by checking file types and ensuring only valid files are processed.

Changes

File Summary
packages/renderless/src/file-upload/index.ts Added a new function isAcceptType to validate file types against accepted types. Modified the upload logic to handle multiple file selections separately, ensuring only valid files are uploaded. Introduced a new parameter isMergeUpload to control the upload behavior.

const isAcceptType = (acceptArray, file, constants) => {
return acceptArray.some((type) => {
if (type.toLowerCase() === constants.IMAGE_TYPE) {
return constants.FILE_TYPE.PICTURE.split('/').includes(fileType)

Choose a reason for hiding this comment

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

fileType is used here without being defined in the scope of isAcceptType. This will lead to a reference error. Ensure fileType is properly defined or passed to the function.

@chenxi-20 chenxi-20 changed the title fix(file-upload): Fix bug in file upload component where multiple selections are merge-service and uploaded fix(file-upload): Fix bug in file-upload component where multiple selections are merge-service and uploaded May 14, 2025
Copy link

@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)
packages/renderless/src/file-upload/index.ts (1)

253-253: Add proper type annotation for the isMergeUpload parameter.

The function signature has been updated with a new parameter isMergeUpload but it lacks a type annotation, which is inconsistent with the other parameters.

Apply this fix:

- (file: IFileUploadFile, autoRemove: boolean, doUpload: Function, isMergeUpload) => {
+ (file: IFileUploadFile, autoRemove: boolean, doUpload: Function, isMergeUpload: boolean) => {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7fc60b1 and b6eb3a3.

📒 Files selected for processing (1)
  • packages/renderless/src/file-upload/index.ts (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: PR E2E Test (pnpm test:e2e3)
🔇 Additional comments (1)
packages/renderless/src/file-upload/index.ts (1)

266-286: The file filtering logic for merged uploads is a solid improvement.

The implementation correctly handles both merged and single file upload scenarios:

  1. For merged uploads, it filters out files that don't match the accept types
  2. For single file uploads, it maintains the original validation behavior

This should effectively fix the issue where multiple file selections could include invalid files when merged.

@@ -612,7 +631,7 @@
const handler = (file) =>
vm.$refs[constants.UPLOAD_INNER].$refs[constants.UPLOAD_INNER_TEMPLATE].upload(file.raw)

rawFiles.length && api.beforeUpload({ raw: rawFiles }, true, handler)
rawFiles.length && api.beforeUpload({ raw: rawFiles }, true, handler, true)
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify this implementation properly handles all edge cases.

The fix for the multiple file selection bug looks good, but please verify that this implementation properly handles all edge cases, especially when:

  1. Some files in the selection are invalid
  2. All files in the selection are invalid
  3. Very large batches of files are selected at once

Run the following test to verify the behavior:


🏁 Script executed:

#!/bin/bash
# Search for all usages of beforeUpload and check for any potential edge cases

# Look for places where beforeUpload is called
rg "beforeUpload\(" --type ts -A 3 -B 3

Length of output: 5563


🏁 Script executed:

#!/bin/bash
# Extract definition of beforeUpload in file-upload/index.ts
rg -n "export.*beforeUpload" -A50 packages/renderless/src/file-upload/index.ts
rg -n "const beforeUpload" -A50 packages/renderless/src/file-upload/index.ts
rg -n "function beforeUpload" -A50 packages/renderless/src/file-upload/index.ts

Length of output: 3909


🏁 Script executed:

#!/bin/bash
# Print lines 290 to 360 of beforeUpload implementation for full context
sed -n '290,360p' packages/renderless/src/file-upload/index.ts

Length of output: 1961


Ensure beforeUpload fully covers merge‐upload edge cases

I’ve reviewed the beforeUpload implementation in
packages/renderless/src/file-upload/index.ts around the multiple‐file branch:

// caller for merged uploads
rawFiles.length && api.beforeUpload({ raw: rawFiles }, true, handler, true)

The isMergeUpload path currently:

  • Silently filters out invalid files via remove({ …file: f })
  • Does not early‐exit if all files are invalid (it will still invoke props.beforeUpload/doUpload with an empty raw array)
  • Suppresses user feedback for each invalid file, unlike the single‐file path which shows a warning

Please adjust to handle these scenarios:

• Some invalid files:
– After filtering, if file.raw.length < originalCount, display a warning (e.g. “3 of 5 files were rejected.”)
• All invalid files:
– If file.raw.length === 0, abort and show a consolidated Modal message, do not call beforeUpload/doUpload
• Very large batches:
– Confirm that a large rawFiles array does not degrade performance—consider batching or deferring UI updates if necessary

Suggested diff snippet:

   if (isMergeUpload) {
     const originalCount = file.raw.length
     const fileRow: File[] = []
     file.raw.flatMap(f => {
       if (accept && !isAcceptType(acceptArray, f, constants)) {
-        remove({ api, file: f, autoRemove })
+        remove({ api, file: f, autoRemove })
       } else {
         fileRow.push(f)
       }
       return getFileType({ file: f })
     })
     file.raw = fileRow

+    // edge‐case: no valid files left
+    if (file.raw.length === 0) {
+      return Modal.message({
+        message: t(constants.EDM.NO_VALID_FILES_SELECTED),
+        status: 'warning'
+      })
+    }
+
+    // edge‐case: some files invalid
+    if (file.raw.length < originalCount) {
+      Modal.message({
+        message: t(constants.EDM.SOME_FILES_REJECTED, { count: originalCount - file.raw.length }),
+        status: 'warning'
+      })
+    }
   }

These changes will ensure that users get clear, consolidated feedback and that we never proceed with an empty upload.

@chenxi-20 chenxi-20 force-pushed the fix/file-upload-20250514 branch from b6eb3a3 to 3f7b9a7 Compare May 14, 2025 09:15
@chenxi-20 chenxi-20 force-pushed the fix/file-upload-20250514 branch from 3f7b9a7 to fe7ea25 Compare May 14, 2025 09:26
@zzcr zzcr merged commit 455e55b into dev May 16, 2025
5 checks passed
@zzcr zzcr deleted the fix/file-upload-20250514 branch May 16, 2025 01:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants