-
-
Notifications
You must be signed in to change notification settings - Fork 227
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: popup glitch when not enough width #510
base: master
Are you sure you want to change the base?
Conversation
Walkthrough本次变更修改了 Changes
Possibly related PRs
Suggested reviewers
Poem
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
src/hooks/useAlign.tsOops! Something went wrong! :( ESLint: 8.57.1 ESLint couldn't find the plugin "eslint-plugin-react". (The package "eslint-plugin-react" 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:
The plugin "eslint-plugin-react" was referenced from the config file in ".eslintrc.js » /node_modules/.pnpm/@umijs[email protected][email protected]/node_modules/@umijs/fabric/dist/eslint.js". If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team. ✨ Finishing Touches
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 (2)
src/hooks/useAlign.ts (2)
292-297
: 建议优化 scale 计算的性能当前实现中对 width 和 height 的解析和计算可以进一步优化:
-const scaleX = toNum( - Math.round((popupWidth / parseFloat(width)) * 1000) / 1000, -); -const scaleY = toNum( - Math.round((popupHeight / parseFloat(height)) * 1000) / 1000, -); +const parseAndRound = (value: string) => parseFloat(value); +const scaleX = toNum(Math.round((popupWidth / parseAndRound(width)) * 1000) / 1000); +const scaleY = toNum(Math.round((popupHeight / parseAndRound(height)) * 1000) / 1000);
300-306
: 验证 scale 为 0 的边界情况处理当 scale 为 0 时提前返回是个好的做法,但建议添加日志以便于调试。
if ( scaleX === 0 || scaleY === 0 || (isDOM(target) && !isVisible(target)) ) { + if (process.env.NODE_ENV !== 'production') { + console.warn('Skip align since element has zero scale or target is not visible'); + } return; }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/hooks/useAlign.ts
(2 hunks)
🔇 Additional comments (1)
src/hooks/useAlign.ts (1)
170-170
: 修复了维度计算的时序问题将
width
和height
的获取移到 popupElement 重置之后是正确的做法,这样可以确保获取到准确的维度值用于后续的对齐计算。Also applies to: 221-221
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #510 +/- ##
=======================================
Coverage 97.75% 97.75%
=======================================
Files 13 13
Lines 800 801 +1
Branches 235 231 -4
=======================================
+ Hits 782 783 +1
Misses 18 18 ☔ View full report in Codecov by Sentry. |
ping @zombieJ |
This is a fix for #496 which was introduced in #419
That change moved setting the height/width to before the popupElement reset, which makes the calculations that use height/width incorrect. Moving the height/width assignment back to after the popupElement reset fixes the glitch caused by incorrect calculations.
Summary by CodeRabbit