Skip to content

fix: optimize and fix the implementation of emptyNode shake #1273

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

Merged
merged 1 commit into from
May 15, 2025

Conversation

linxianxi
Copy link
Contributor

@linxianxi linxianxi commented May 15, 2025

优化 #1142 的实现,用 useLayoutEffect 获取宽度解决不同步的问题。

用 ResizeObserver 几乎都有这个问题,比如其他地方有用到宽度,需要 useLayoutEffect 获取一下避免闪烁。

Summary by CodeRabbit

  • 修复
    • 优化了表格在水平滚动状态变化时的自适应宽度调整,提升了表格在不同场景下的显示效果。
    • 修正了展开行在特定条件下的可见性样式问题,确保内容显示更加一致。

Copy link

vercel bot commented May 15, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
table ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 15, 2025 3:00am

Copy link

coderabbitai bot commented May 15, 2025

Walkthrough

本次更改主要涉及表格组件的样式与尺寸调整逻辑。移除了 ExpandedRow 组件根节点的 visibility 样式控制,并重构了 Table 组件的表格宽度调整逻辑,包括更新回调参数和增加响应横向滚动变化的副作用。

Changes

文件/分组 变更摘要
src/Body/ExpandedRow.tsx 移除了根节点根据特定条件设置 visibility: hidden 的样式逻辑。
src/Table.tsx onFullTableResize 参数由对象改为可选数字,调整宽度计算逻辑;增加 useLayoutEffect 以响应横向滚动状态变化;更新 ResizeObserver 回调参数传递方式。

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Table
    participant ResizeObserver
    participant DOM

    User->>DOM: 触发表格尺寸变化(如窗口缩放/横向滚动)
    DOM-->>ResizeObserver: 触发 onResize(offsetWidth)
    ResizeObserver->>Table: onFullTableResize(offsetWidth)
    Table->>Table: 计算 mergedWidth 并更新状态
    Table->>DOM: 重新渲染表格宽度
    Note over Table: horizonScroll 变化时 useLayoutEffect 触发 onFullTableResize
Loading

Possibly related PRs

Suggested reviewers

  • afc163
  • zombieJ

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/Table.tsx

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the config "prettier" to extend from. Please check that the name of the config is correct.

The config "prettier" was referenced from the config file in "/.eslintrc.js".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b4ceb29 and e742bbd.

⛔ Files ignored due to path filters (2)
  • tests/__snapshots__/ExpandRow.spec.jsx.snap is excluded by !**/*.snap
  • tests/__snapshots__/FixedColumn.spec.tsx.snap is excluded by !**/*.snap
📒 Files selected for processing (2)
  • src/Body/ExpandedRow.tsx (0 hunks)
  • src/Table.tsx (3 hunks)
💤 Files with no reviewable changes (1)
  • src/Body/ExpandedRow.tsx
🔇 Additional comments (3)
src/Table.tsx (3)

498-500: 优化了 onFullTableResize 函数的参数处理

函数现在接受可选的数值参数 offsetWidth 而不是对象,这样简化了代码并提高了可读性。合理地使用了空值合并运算符来处理参数缺失的情况。


511-516: 修复了水平滚动状态变化时表格宽度不更新的问题

添加了 useLayoutEffect 钩子来监听 horizonScroll 变化,这确保了当水平滚动状态改变时立即更新表格宽度。使用 useLayoutEffect 而不是 useEffect 是正确的,因为这保证了在浏览器绘制前同步更新 DOM。


809-813: 简化了 ResizeObserver 的回调处理

现在直接传递 offsetWidth 参数给 onFullTableResize 函数,而不是传递整个事件对象,这与函数签名的变化保持一致,使代码更加简洁。

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need 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)

  • @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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @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.

Copy link

codecov bot commented May 15, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.03%. Comparing base (b4ceb29) to head (e742bbd).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1273   +/-   ##
=======================================
  Coverage   98.03%   98.03%           
=======================================
  Files          76       76           
  Lines        7428     7435    +7     
  Branches     1144     1147    +3     
=======================================
+ Hits         7282     7289    +7     
  Misses        140      140           
  Partials        6        6           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@afc163 afc163 merged commit 92dbe91 into react-component:master May 15, 2025
9 checks passed
@afc163
Copy link
Member

afc163 commented May 15, 2025

fix ant-design/ant-design#49279

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.

2 participants