Skip to content

fix(components): [upload] make abort param optional#23353

Merged
btea merged 2 commits into
element-plus:devfrom
SevenDreamYang:upload-abort-param-optional
Jan 9, 2026
Merged

fix(components): [upload] make abort param optional#23353
btea merged 2 commits into
element-plus:devfrom
SevenDreamYang:upload-abort-param-optional

Conversation

@SevenDreamYang
Copy link
Copy Markdown
Contributor

@SevenDreamYang SevenDreamYang commented Jan 8, 2026

  • Change the parameter type definition of the abort function to optional

Please make sure these boxes are checked before submitting your PR, thank you!

  • Make sure you follow contributing guide English | (中文 | Español | Français).
  • Make sure you are merging your commits to dev branch.
  • Add some descriptions and refer to relative issues for your PR.

Instructions

  • When calling the abort function in the upload-content.vue file, the parameters are optional, but in use-handlers.ts, the parameters of the abort function are defined as mandatory parameters, resulting in type mismatch.

Summary by CodeRabbit

  • New Features

    • Upload component's abort functionality is now more flexible, allowing calls without specifying a file.
  • Documentation

    • Updated Upload component documentation to reflect API changes.

✏️ Tip: You can customize this high-level summary in your review settings.

- Change the parameter type definition of the �bort function to optional
@pull-request-triage
Copy link
Copy Markdown

👋 @SevenDreamYang, seems like this is your first time contribution to element-plus.
Please make sure that you have read our guidelines and code of conduct before making a contribution.

@pull-request-triage pull-request-triage Bot added 1st contribution Their very first contribution Needs Review labels Jan 8, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 8, 2026

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 8, 2026

📝 Walkthrough

Walkthrough

The abort function parameter in the Upload component is made optional across documentation and implementation. The function signature changes from requiring a file parameter to accepting an optional one, allowing the abort method to be called without arguments.

Changes

Cohort / File(s) Summary
Implementation
packages/components/upload/src/use-handlers.ts
Function signature updated: abort(file: UploadFile)abort(file?: UploadFile) making the file parameter optional
Documentation
docs/en-US/component/upload.md
Exposes table updated to reflect signature change: abort(file: UploadFile) => voidabort(file?: UploadFile) => void

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A parameter once bound and constrained,
Now flexible, beautifully unchained,
Abort may stand solo and free,
Optional dancing through the spree,
With a hop and a skip, we declare—
The Upload's grown lighter than air! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: making the abort function parameter optional in the upload component.
Description check ✅ Passed The description includes the required checklist items, explains the change rationale, references specific files and line numbers, and addresses the type mismatch issue.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8b7d8ea and e653661.

📒 Files selected for processing (2)
  • docs/en-US/component/upload.md
  • packages/components/upload/src/use-handlers.ts
🧰 Additional context used
🧬 Code graph analysis (1)
packages/components/upload/src/use-handlers.ts (1)
packages/components/upload/src/upload.ts (1)
  • UploadFile (31-40)
🔇 Additional comments (2)
docs/en-US/component/upload.md (1)

149-149: LGTM! Documentation correctly reflects the API change.

The abort function signature update accurately documents that the file parameter is now optional, aligning with the implementation change in use-handlers.ts.

packages/components/upload/src/use-handlers.ts (1)

42-44: Optional parameter is correctly implemented and backward compatible.

The abort() method in upload-content.vue properly handles undefined as a parameter:

  • When called without arguments: aborts all uploads (filter matches all requests)
  • When called with a specific file: aborts only that file's upload (filter matches by uid)

The implementation uses conditional filtering logic:

const abort = (file?: UploadFile) => {
  const _reqs = entriesOf(requests.value).filter(
    file ? ([uid]) => String(file.uid) === uid : () => true
  )
  _reqs.forEach(([uid, req]) => {
    if (req instanceof XMLHttpRequest) req.abort()
    delete requests.value[uid]
  })
}

The wrapper in use-handlers.ts correctly exposes this with an optional parameter, and the only call site found (remove handler) passes a specific file, which is the expected usage.


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

@E66Crisp
Copy link
Copy Markdown
Contributor

E66Crisp commented Jan 9, 2026

Hi, I think these two functions serve different purposes. The abort in use-handlers.ts is a higher-level wrapper, while upload-content.vue's is the underlying implementation. They don't need to have the same signature. Just my personal opinion.

@SevenDreamYang
Copy link
Copy Markdown
Contributor Author

SevenDreamYang commented Jan 9, 2026

Hi, I think these two functions serve different purposes. The abort in use-handlers.ts is a higher-level wrapper, while upload-content.vue's is the underlying implementation. They don't need to have the same signature. Just my personal opinion.

Thank you very much for reviewing. We have a product requirement to abort all ongoing file uploads when the user navigates away from the page.I’ve reviewed the implementation of the abort method: when a file is provided, it aborts only the upload matching file.uid; when no argument is passed, it aborts all pending uploads via the () => true filter.
However, the current TypeScript type definition requires the file parameter to be passed, even though the runtime logic already supports an optional parameter.

image

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Jan 9, 2026

Open in StackBlitz

pnpm add https://pkg.pr.new/element-plus/element-plus@23353
npm i https://pkg.pr.new/element-plus/element-plus@23353
yarn add https://pkg.pr.new/element-plus/[email protected]

commit: 527042d

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 9, 2026

🧪 Playground Preview: https://element-plus.run/?pr=23353
Please comment the example via this playground if needed.

Copy link
Copy Markdown
Member

@rzzf rzzf left a comment

Choose a reason for hiding this comment

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

looks good to me

@btea btea enabled auto-merge (squash) January 9, 2026 13:34
@btea btea merged commit c6e2ed6 into element-plus:dev Jan 9, 2026
16 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 9, 2026

@SevenDreamYang Thanks for your contribution! ❤️

@element-bot element-bot mentioned this pull request Jan 30, 2026
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants