-
Notifications
You must be signed in to change notification settings - Fork 268
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: imageSize=0无效 #2937
fix: imageSize=0无效 #2937
Conversation
变更概述演练此次变更主要修改了 变更
可能相关的 PR
建议标签
建议审阅者
诗歌庆祝
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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 (
|
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: 0
🧹 Nitpick comments (1)
src/packages/empty/empty.taro.tsx (1)
Line range hint
72-84
: 实现与非 Taro 版本保持一致!Taro 版本的改动与标准版本完全一致,确保了跨平台行为的一致性。实现方式合理,完全解决了
imageSize=0
的问题。建议:
考虑将这个通用的类型检查逻辑抽取到 utils 文件中,以避免代码重复,提高维护性。// 建议在 utils.ts 中添加: + export const getImageSizeStyle = (imageSize: number | string) => { + if (typeof imageSize !== 'number' && typeof imageSize !== 'string') { + return {} + } + if (typeof imageSize === 'number') { + return { + width: `${imageSize}px`, + height: `${imageSize}px`, + } + } + return { + width: imageSize, + height: imageSize, + } + }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/packages/empty/empty.taro.tsx
(1 hunks)src/packages/empty/empty.tsx
(1 hunks)
🔇 Additional comments (1)
src/packages/empty/empty.tsx (1)
Line range hint
74-86
: 类型检查逻辑优化得当!新的类型检查逻辑解决了
imageSize=0
无效的问题,同时保持了对字符串类型的兼容性。代码结构清晰,类型判断准确。以下是具体改进:
- 通过显式的类型检查替代了原来的真值判断,避免了 0 被错误地判断为假值
- 分别处理了数字和字符串两种有效类型
- 对于无效类型返回空对象,确保了组件的健壮性
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## next #2937 +/- ##
==========================================
+ Coverage 84.02% 84.03% +0.01%
==========================================
Files 220 220
Lines 17917 17917
Branches 2628 2628
==========================================
+ Hits 15055 15057 +2
+ Misses 2857 2855 -2
Partials 5 5 ☔ View full report in Codecov by Sentry. |
🤔 这个变动的性质是?
🔗 相关 Issue
💡 需求背景和解决方案
背景: Empty设置imageSize=0无效
解决:
判断条件改为
typeof imageSize !== 'number' && typeof imageSize !== 'string'
☑️ 请求合并前的自查清单
Summary by CodeRabbit
imageSize
为数字或字符串时正确设置图像样式。