Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jon-cullison
Copy link

@jon-cullison jon-cullison commented Feb 14, 2025

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

  • Refactor
    • 优化了弹出窗口尺寸获取和对齐计算的内部逻辑,简化了代码结构。
    • 调整后的处理方案确保窗口显示与定位保持稳定,用户体验不受影响。

Copy link

coderabbitai bot commented Feb 14, 2025

Walkthrough

本次变更修改了 src/hooks/useAlign.ts 文件中的 useAlign 函数,将原先通过结构赋值从 popupElement 的 computed style 中获取 widthheight 的逻辑移除,改为使用其他方式获取这两个尺寸值。对齐计算及后续逻辑基本保持不变,但新方式的尺寸获取需要确保后续计算依然正确。

Changes

文件 变更说明
src/hooks/useAlign.ts 移除了直接结构赋值提取 widthheight 的代码,改用其他方式赋值尺寸,用于对齐计算

Possibly related PRs

Suggested reviewers

  • afc163

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

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.

src/hooks/useAlign.ts

Oops! 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:

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

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
  • 📝 Generate Docstrings (Beta)

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?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Beta)
  • @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.

@jon-cullison jon-cullison marked this pull request as ready for review February 14, 2025 20:04
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: 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

📥 Commits

Reviewing files that changed from the base of the PR and between a53c077 and 78caaf9.

📒 Files selected for processing (1)
  • src/hooks/useAlign.ts (2 hunks)
🔇 Additional comments (1)
src/hooks/useAlign.ts (1)

170-170: 修复了维度计算的时序问题

widthheight 的获取移到 popupElement 重置之后是正确的做法,这样可以确保获取到准确的维度值用于后续的对齐计算。

Also applies to: 221-221

Copy link

codecov bot commented Feb 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.75%. Comparing base (a9c5ec8) to head (78caaf9).
Report is 1 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

@mellis481
Copy link

@zombieJ @afc163 Can we get this PR merged please?

@afc163
Copy link
Member

afc163 commented Feb 25, 2025

ping @zombieJ

@jon-cullison
Copy link
Author

@zombieJ @afc163 Could we please get this PR merged?

@afc163 afc163 requested a review from zombieJ March 3, 2025 15:18
@yhy-1
Copy link

yhy-1 commented Mar 21, 2025

@zombieJ @afc163 Could we please get this PR merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants