-
-
Notifications
You must be signed in to change notification settings - Fork 618
fix: Table MeasureRow bug when children have refs #1367
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
Conversation
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. ✨ Finishing touches🧪 Generate unit tests
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. Comment |
Summary of ChangesHello @afc163, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses and fixes a specific bug within the Ant Design Table component's measurement system. The core issue arose when column headers were complex React elements that included Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request addresses a bug in the MeasureRow
component that occurs when a column's title is a React element with a ref
. The fix involves cloning the title element and stripping its ref
before measurement, which is a sound approach to prevent React warnings. The accompanying refactoring in MeasureCell
to accept a title
prop instead of the entire column
object is a good improvement for component decoupling. I have one suggestion regarding a potential performance optimization in MeasureRow.tsx
.
}} | ||
> | ||
{columnsKey.map(columnKey => { | ||
const column = columns.find(col => col.key === columnKey); |
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.
Using Array.prototype.find
inside a map
results in an O(N*M) time complexity, where N is the length of columnsKey
and M is the length of columns
. This can lead to performance degradation on tables with a large number of columns.
For better performance, you could create a lookup map from the columns
array before iterating. This would reduce the complexity of finding a column to O(1) inside the loop.
You can achieve this by creating a memoized map at the top level of your component, like so:
const columnsMap = React.useMemo(() => {
const map = new Map<React.Key, (typeof columns)[number]>();
for (const col of columns) {
if (col.key) {
map.set(col.key, col);
}
}
return map;
}, [columns]);
Then, inside your map
function, you can retrieve the column efficiently:
const column = columnsMap.get(columnKey);
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## antd-5.x #1367 +/- ##
=========================================
Coverage 97.69% 97.69%
=========================================
Files 77 77
Lines 7668 7672 +4
Branches 1161 1164 +3
=========================================
+ Hits 7491 7495 +4
Misses 171 171
Partials 6 6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
ant-design/ant-design#55039