-
Notifications
You must be signed in to change notification settings - Fork 273
fix(uploader): beforeUpload failed to work #3219
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
fix(uploader): beforeUpload failed to work #3219
Conversation
""" Walkthrough本次变更主要重构了上传组件中处理 Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Uploader
participant beforeUpload
participant FileReader
User->>Uploader: 选择文件
Uploader->>beforeUpload: (可选) 传递筛选后的文件
alt beforeUpload 存在
beforeUpload-->>Uploader: 返回处理后的文件数组
Uploader->>Uploader: 判断文件数组是否为空
alt 文件数组为空
Uploader->>User: 清空 input,无后续处理
else 文件数组非空
Uploader->>FileReader: 读取文件
end
else beforeUpload 不存在
Uploader->>FileReader: 直接读取文件
end
Possibly related PRs
Suggested reviewers
Poem
Tip ⚡️ Faster reviews with caching
Enjoy the performance boost—your workflow just got faster. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🧰 Additional context used🧠 Learnings (1)src/packages/uploader/__tests__/uploader.spec.tsx (1)
⏰ Context from checks skipped due to timeout of 90000ms (2)
🔇 Additional comments (2)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## feat_v3.x #3219 +/- ##
=============================================
+ Coverage 86.70% 86.72% +0.01%
=============================================
Files 291 291
Lines 19062 19067 +5
Branches 2891 2894 +3
=============================================
+ Hits 16528 16535 +7
+ Misses 2529 2527 -2
Partials 5 5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/packages/uploader/demos/h5/demo1.tsx
(0 hunks)src/packages/uploader/uploader.taro.tsx
(1 hunks)src/packages/uploader/uploader.tsx
(1 hunks)
💤 Files with no reviewable changes (1)
- src/packages/uploader/demos/h5/demo1.tsx
🧰 Additional context used
🪛 GitHub Check: codecov/patch
src/packages/uploader/uploader.tsx
[warning] 166-169: src/packages/uploader/uploader.tsx#L166-L169
Added lines #L166 - L169 were not covered by tests
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: test
🔇 Additional comments (2)
src/packages/uploader/uploader.tsx (1)
173-173
: 修复了文件过滤顺序问题这个修改非常关键 - 您现在对
_files
进行过滤(即beforeUpload
处理后的结果),而不是原始文件数组。这确保了beforeUpload
钩子函数对文件的任何修改都会被正确地应用到后续的过滤逻辑中。这个修改很好地解决了
beforeUpload
功能无法正常工作的问题。src/packages/uploader/uploader.taro.tsx (1)
319-328
: 优化了 Taro 端的 beforeUpload 处理逻辑您改进了
onChangeImage
函数中的beforeUpload
处理流程,使用 Promise 链式调用替代了之前的方式。这种实现方式更加清晰,并且与 Web 端的实现保持一致。关键改进包括:
- 直接将筛选后的
_files
数组传递给beforeUpload
- 正确处理
beforeUpload
返回空数组的情况- 简化了条件分支逻辑
这个改动很好地解决了
beforeUpload
钩子在 Taro 环境中不能正常工作的问题。
🤔 这个变动的性质是?
🔗 相关 Issue
💡 需求背景和解决方案
☑️ 请求合并前的自查清单
Summary by CodeRabbit