Skip to content

refactor(table): refactor spinProps with useMemo#55344

Merged
li-jia-nan merged 3 commits intomasterfrom
spinProps-update
Oct 18, 2025
Merged

refactor(table): refactor spinProps with useMemo#55344
li-jia-nan merged 3 commits intomasterfrom
spinProps-update

Conversation

@li-jia-nan
Copy link
Copy Markdown
Member

中文版模板 / Chinese template

🤔 This is a ...

  • 🆕 New feature
  • 🐞 Bug fix
  • 📝 Site / documentation improvement
  • 📽️ Demo improvement
  • 💄 Component style improvement
  • 🤖 TypeScript definition improvement
  • 📦 Bundle size optimization
  • ⚡️ Performance optimization
  • ⭐️ Feature enhancement
  • 🌐 Internationalization
  • 🛠 Refactoring
  • 🎨 Code style optimization
  • ✅ Test Case
  • 🔀 Branch merge
  • ⏩ Workflow
  • ⌨️ Accessibility improvement
  • ❓ Other (about what?)

🔗 Related Issues

  • Describe the source of related requirements, such as links to relevant issue discussions.
  • For example: close #xxxx, fix #xxxx

💡 Background and Solution

  • The specific problem to be addressed.
  • List the final API implementation and usage if needed.
  • If there are UI/interaction changes, consider providing screenshots or GIFs.

📝 Change Log

Language Changelog
🇺🇸 English refactor(table): refactor spinProps with useMemo
🇨🇳 Chinese refactor(table): refactor spinProps with useMemo

@bolt-new-by-stackblitz
Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Oct 17, 2025

👁 Visual Regression Report for PR #55344 Passed ✅

🎯 Target branch: master (da79662)
📖 View Full Report ↗︎
📖 Alternative Report ↗︎

🎊 Congrats! No visual-regression diff found.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Oct 17, 2025

Preview is ready

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @li-jia-nan, 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 introduces a refactoring to the InternalTable component, primarily focusing on optimizing the handling of loading states and improving type definitions. By leveraging React's useMemo hook, it aims to enhance performance and maintainability of the table component.

Highlights

  • Performance Optimization: The spinProps calculation within the InternalTable component has been refactored to use React.useMemo. This change memoizes the spinProps object, preventing its re-creation on every render and optimizing performance by reducing unnecessary object allocations and re-renders when the loading prop remains unchanged.
  • Type Clarity: The mergedEmptyNode memoization now explicitly defines its return type within React.useMemo, improving type inference and code clarity for the emptyText prop of RcTableProps.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Oct 17, 2025

Note

Other AI code review bot(s) detected

CodeRabbit 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.

📝 Walkthrough

Summary by CodeRabbit

发布说明

  • 性能优化

    • 优化了表格组件的加载状态和空状态处理,减少了不必要的重新计算,提升了应用性能。
  • 测试

    • 更新了表格加载状态测试用例,确保功能的稳定性。

Walkthrough

components/table/InternalTable.tsx 中,将原基于 IIFE 的 spinProps 与 mergedEmptyNode 计算改为使用 React.useMemo 并补充了对 loading 的显式空值判断;测试中将 loading 配置直接内联为对象字面量以移除可变中间变量。

Changes

Cohort / File(s) 变更摘要
表格核心逻辑
components/table/InternalTable.tsx
将 spinProps 计算改为 React.useMemo(依赖 loading),保留 boolean 路径并对对象路径使用 null-guarded spread;将 mergedEmptyNode 使用带类型的 React.useMemo 计算并加入 guard(若 spinProps?.spinningrawData === EMPTY_LIST 则返回 null);调整 emptyText 判定逻辑以保留 locale.emptyText 分支。
单元测试调整
components/table/__tests__/Table.test.tsx
在 “loading with Spin” 测试中,移除对同一可变对象的创建与变更,改为直接使用内联的 loading 对象字面量以简化测试流程(逻辑与断言未变)。

Sequence Diagram(s)

(本次修改为局部重构/优化,控制流未新增或显著改变,故不提供时序图。)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 分钟

Possibly related PRs

Suggested labels

skip-verify-files

Suggested reviewers

  • afc163
  • zombieJ
  • crazyair

Poem

🐰 我在代码园中蹦跳,轻轻换了 memo 的袍,
渲染少了几次跑,空态在忙时躲一躲,
测试也更直白好看,兔兔悄悄竖耳笑。

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed PR标题"refactor(table): refactor spinProps with useMemo"准确反映了changeset的主要改动。根据原始总结,核心变更是将InternalTable.tsx中基于IIFE的spinProps计算替换为React.useMemo,并对mergedEmptyNode进行了类似的memoization重构。标题明确且具体,包含了具体的组件名称(table)和改动内容(spinProps with useMemo),使得扫描历史记录的开发者能够清楚地理解主要变更。
Description Check ✅ Passed PR描述虽然大部分是模板占位符,但与changeset存在相关性。作者选择了"🛠 Refactoring"类型,这与PR的重构性质相符。在"Change Log"部分填写了"refactor(table): refactor spinProps with useMemo"作为中英文日志,直接关联了具体的改动内容。虽然"Background and Solution"等关键部分未详细填写,但现有内容足以证明描述与changeset的关联性。
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch spinProps-update

📜 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 a768fbc and 59322e7.

📒 Files selected for processing (2)
  • components/table/InternalTable.tsx (2 hunks)
  • components/table/__tests__/Table.test.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/table/InternalTable.tsx
🧰 Additional context used
📓 Path-based instructions (5)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{ts,tsx}: Use TypeScript and React; prefer functional components and Hooks over class components
Component names must use PascalCase; prop names use camelCase
Prefer early returns to improve readability
Use React.memo, useMemo, and useCallback appropriately for performance optimization
All components and functions must have accurate type definitions; avoid any; prefer interfaces over type aliases for object shapes
Export all public interface types for consumer usage
Component props must be defined using interface named ComponentNameProps; define state via a dedicated interface (e.g., ComponentNameState)
Define ref types explicitly; use React.ForwardRefRenderFunction for components with refs
Define callback function parameter and return types explicitly
Use generics appropriately; use intersection types (&); prefer literal union types for finite options; avoid enum in favor of unions and as const; rely on inference; use assertions only when necessary
Support SSR and React 16–19 compatibility in component code
Support RTL and dark mode; prefer CSS logical properties (e.g., margin-inline-start) over directional ones
Use CSS transitions for simple animations and rc-motion for complex ones; respect prefers-reduced-motion; keep durations/easings consistent
Ensure accessibility styling: visible focus, sufficient color contrast, avoid color-only cues, avoid flashing animations, support 200% zoom
Components should expose a ref with shape { nativeElement: HTMLElement; focus: VoidFunction; ... }
Avoid introducing new dependencies; keep bundle size controlled; support tree-shaking
Avoid deprecated APIs; update to recommended APIs
Pass all ESLint and TypeScript checks with zero type errors or warnings; use TypeScript strict mode

**/*.{ts,tsx}: Do not use the any type; define precise types instead
Use interface (not type aliases) for object structures
Export all public interface types
Prefer union types over enums; use as const for constants
Use early returns to i...

Files:

  • components/table/__tests__/Table.test.tsx
**/__tests__/**/*.test.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/__tests__/**/*.test.{ts,tsx}: Place unit tests in tests with filenames ending in .test.tsx or .test.ts; use Jest and React Testing Library; include snapshot tests for UI components
Achieve 100% test coverage for tests

Files:

  • components/table/__tests__/Table.test.tsx
components/*/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

components/*/**/*.{ts,tsx}: Name component props interfaces as ComponentNameProps
Never hardcode colors, sizes, or spacing values

Files:

  • components/table/__tests__/Table.test.tsx
**/__tests__/**/*.test.tsx

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/__tests__/**/*.test.tsx: Write tests using Jest and React Testing Library
Place tests in __tests__ directories as index.test.tsx or componentName.test.tsx
Include snapshot tests for UI components

Files:

  • components/table/__tests__/Table.test.tsx
components/*/**

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Place each component under components/[component-name]/

Files:

  • components/table/__tests__/Table.test.tsx
🧠 Learnings (1)
📓 Common learnings
Learnt from: CR
PR: ant-design/ant-design#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-17T14:39:13.414Z
Learning: Applies to components/*/**/*.{tsx} : Optimize with React.memo, useMemo, and useCallback where appropriate
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (17)
  • GitHub Check: build preview
  • GitHub Check: test lib/es module (es, 1/2)
  • GitHub Check: test lib/es module (es, 2/2)
  • GitHub Check: test-react-latest (dom, 2/2)
  • GitHub Check: test-react-legacy (17, 1/2)
  • GitHub Check: build
  • GitHub Check: test-react-legacy (17, 2/2)
  • GitHub Check: test-react-latest (dom, 1/2)
  • GitHub Check: test-react-legacy (16, 2/2)
  • GitHub Check: build
  • GitHub Check: lint
  • GitHub Check: test-react-legacy (16, 1/2)
  • GitHub Check: visual-diff snapshot (2/2)
  • GitHub Check: visual-diff snapshot (1/2)
  • GitHub Check: size
  • GitHub Check: build
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (1)
components/table/__tests__/Table.test.tsx (1)

75-78: LGTM!重构改进了测试代码质量。

使用内联对象字面量替代可变中间变量是一个很好的改进:

  • 避免了对象突变,符合 React 不可变性原则
  • 使每次渲染的意图更加明确和清晰
  • 与 InternalTable.tsx 中使用 useMemo 的重构保持一致
  • 测试逻辑保持不变且正确

这种写法更利于 React 的依赖追踪和重新渲染优化。


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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a 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 refactors the spinProps calculation within the InternalTable component to leverage React.useMemo. This is a positive change for performance, as it memoizes the props and prevents re-computation on every render, only re-evaluating when the loading prop changes. The implementation is sound. I have one suggestion to enhance the type definition for improved clarity.

Comment thread components/table/InternalTable.tsx Outdated
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: lijianan <574980606@qq.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Oct 17, 2025

size-limit report 📦

Path Size
dist/antd.min.js 445.38 KB (+3 B 🔺)
dist/antd-with-locales.min.js 532.64 KB (+2 B 🔺)

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Oct 17, 2025

@coderabbitai coderabbitai Bot added the lgtm This PR has been approved by a maintainer label Oct 17, 2025
@codecov
Copy link
Copy Markdown

codecov Bot commented Oct 17, 2025

Bundle Report

Changes will increase total bundle size by 6.31MB (186.59%) ⬆️⚠️, exceeding the configured threshold of 5%.

Bundle name Size Change
antd.min-array-push 9.69MB 6.31MB (186.59%) ⬆️⚠️

Affected Assets, Files, and Routes:

view changes for bundle: antd.min-array-push

Assets Changed:

Asset Name Size Change Total Size Change (%)
antd-with-locales.js (New) 5.1MB 5.1MB 100.0% 🚀
antd.js (New) 4.59MB 4.59MB 100.0% 🚀
antd-with-locales.min.js (Deleted) -1.85MB 0 bytes -100.0% 🗑️
antd.min.js (Deleted) -1.54MB 0 bytes -100.0% 🗑️

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Oct 17, 2025

Deploying ant-design with  Cloudflare Pages  Cloudflare Pages

Latest commit: 59322e7
Status: ✅  Deploy successful!
Preview URL: https://b3aadba7.ant-design.pages.dev
Branch Preview URL: https://spinprops-update.ant-design.pages.dev

View logs

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Oct 17, 2025

Deploying ant-design-next with  Cloudflare Pages  Cloudflare Pages

Latest commit: 59322e7
Status: ✅  Deploy successful!
Preview URL: https://c6ce9abc.ant-design-next.pages.dev
Branch Preview URL: https://spinprops-update.ant-design-next.pages.dev

View logs

@codecov
Copy link
Copy Markdown

codecov Bot commented Oct 17, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (da79662) to head (59322e7).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##            master    #55344    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files          777       776     -1     
  Lines        14541     14136   -405     
  Branches      3923      3758   -165     
==========================================
- Hits         14541     14136   -405     

☔ 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.

expect(container.querySelectorAll('.ant-spin')).toHaveLength(0);
expect(container.querySelector('.ant-table-placeholder')?.textContent).not.toEqual('');

loading.spinning = true;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

之前这个用例是有问题的,直接修改了原始对象的属性,导致引用没有变化,React 认为 props 没有变化,不会触发组件内部的 useEffect

@li-jia-nan li-jia-nan merged commit 54afae7 into master Oct 18, 2025
48 checks passed
@li-jia-nan li-jia-nan deleted the spinProps-update branch October 18, 2025 02:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer skip-verify-files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants