Skip to content

Conversation

echoyl
Copy link
Contributor

@echoyl echoyl commented Sep 3, 2025

Summary by CodeRabbit

  • 新增修复

    • 未使用前后缀的表单项中,help 文案现可正常显示,避免误触发函数式渲染导致的缺失或异常。
  • 重构

    • 简化无前后缀场景的渲染逻辑,改用默认渲染;保留含前后缀场景的增强渲染与函数式 help 行为,提升一致性与可维护性。
  • 杂务

    • 无公开 API 变更。

@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Sep 3, 2025
Copy link

coderabbitai bot commented Sep 3, 2025

📝 Walkthrough

Walkthrough

在 FormItem 组件中,调整无 addon 分支的渲染:启用常规 help 属性渲染,移除 _internalItemRender 覆写;带 addon 分支仍保留 _internalItemRender,并仅在此分支支持函数式 help 渲染。未改动任何公开 API 签名。

Changes

Cohort / File(s) Summary
FormItem 渲染路径调整
src/form/components/FormItem/index.tsx
无 addon 路径:启用普通 help 传递,移除 _internalItemRender 覆写;带 addon 路径:继续使用 _internalItemRender 包裹 addonBefore/After,并在 help 为函数时使用函数式渲染;函数式 help 仅限 addon 路径;无公开 API 变更。

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User as 使用者
  participant FormItem as Form.Item
  participant Renderer as 默认渲染
  participant AddonWrap as _internalItemRender(带addon)
  participant HelpFn as help(函数)

  User->>FormItem: 渲染请求(props: addonBefore/After?, help)
  alt 带 addon
    FormItem->>AddonWrap: 使用 _internalItemRender 包裹输入框
    alt help 为函数
      AddonWrap->>HelpFn: 调用 help(props)
      HelpFn-->>AddonWrap: 返回节点
    else help 非函数/未提供
      AddonWrap->>AddonWrap: 传递 help 作为普通节点/空
    end
    AddonWrap-->>User: 输出带 addon 的表单项
  else 无 addon
    FormItem->>Renderer: 使用默认渲染
    Renderer->>Renderer: 直接传入 help(仅普通值)
    note right of Renderer: 不调用函数式 help
    Renderer-->>User: 输出普通表单项
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

我把胡萝卜当作小图标,轻轻点缀输入框旁;
addon 路径留密方,help 可变戏法亮。
无 addon 走坦荡,直传提示不绕墙;
代码耳语风中响,表单更清爽。 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit 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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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

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

Summary of Changes

Hello @echoyl, 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!

此拉取请求旨在解决 FormItem 组件中 help 属性失效的问题。通过取消对相关代码的注释并移除冗余的注释块,确保了表单项的帮助信息能够正确显示,从而提升了用户界面的可用性。

Highlights

  • 修复 FormItem 的 help 属性问题: 恢复了 Form.Item 组件中 help 属性的正确处理,移除了之前注释掉的代码,确保 help 属性能够正常生效。
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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

Copy link

@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

这个 PR 修复了 FormItem 在没有 addonBefore/addonAfterhelp 属性不生效的问题。通过取消注释 help 属性的传递,使得 ReactNode 类型的 help 可以正常工作。然而,当 help 是一个函数时,问题依然存在。我建议进行修改以同时支持函数类型的 help,确保功能完整性。

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/form/components/FormItem/index.tsx (1)

210-260: 重复展开 {...props} 会覆盖已过滤的 help,存在运行时风险

在 addon 分支中,先设置了过滤后的 help(仅非函数),但紧接着再次 {...props}(见 Line 255),会把原始 props.help(可能是函数)重新传入 Form.Item。若最终传给 Form.Item 的 help 为函数,React 可能抛出 “Functions are not valid as a React child” 的运行时错误;同时也可能无意覆盖 _internalItemRendervaluePropName 等属性。建议移除第二次展开:

       <Form.Item
         {...props}
         help={typeof help !== 'function' ? help : undefined}
         valuePropName={valuePropName}
         // @ts-ignore
         _internalItemRender={{
           mark: 'pro_table_render',
           render: (
             inputProps: FormItemProps & {
               errors: React.ReactNode[];
               warnings: React.ReactNode[];
             },
             doms: {
               input: JSX.Element;
               errorList: JSX.Element;
               extra: JSX.Element;
             },
           ) => (
             <>
               ...
             </>
           ),
         }}
-        {...props}
         getValueProps={getValuePropsFunc}
       >
🧹 Nitpick comments (3)
src/form/components/FormItem/index.tsx (3)

196-207: 确认行为变更:无 addon 分支不再支持函数型 help

现在仅 addon 分支会执行函数型 help,无 addon 分支会忽略函数型 help。请确认这是预期(并在变更说明中注明),或考虑在无 addon 时按需启用自定义渲染以保持两条路径一致性。我可以帮你补一组用例覆盖“有/无 addon × help 为节点/函数”四种情况。


245-251: 自定义 help 返回空值时丢失错误列表,建议回退到默认 errorList

当前当 help 为函数时,直接用函数结果替代 doms.errorList。若函数返回 null/undefined,默认错误列表会被吞掉。可以加一个空值回退:

-              {typeof help === 'function'
-                ? help({
-                    errors: inputProps.errors,
-                    warnings: inputProps.warnings,
-                  })
-                : doms.errorList}
+              {typeof help === 'function'
+                ? (help({
+                    errors: inputProps.errors,
+                    warnings: inputProps.warnings,
+                  }) ?? doms.errorList)
+                : doms.errorList}

262-263: useMemo 依赖包含整个 props,实际失去 memo 意义

[addonAfter, addonBefore, children, convertValue?.toString(), props] 中的 props 引用每次渲染都会变化,导致 formDom 基本每次重建。可选优化:改为精确依赖(仅列出用到的 props 字段)或干脆移除 useMemo。

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 0660acf and 466bd28.

📒 Files selected for processing (1)
  • src/form/components/FormItem/index.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{tsx,jsx}

📄 CodeRabbit inference engine (.cursor/rules/react.mdc)

**/*.{tsx,jsx}: Use early returns whenever possible to make the code more readable.
Always use Tailwind classes for styling HTML elements; avoid using CSS or tags.
Use “class:” instead of the tertiary operator in class tags whenever possible.
Use descriptive variable and function/const names. Also, event functions should be named with a “handle” prefix, like “handleClick” for onClick and “handleKeyDown” for onKeyDown.
Implement accessibility features on elements. For example, a tag should have a tabindex=“0”, aria-label, on:click, and on:keydown, and similar attributes.
Use consts instead of functions, for example, “const toggle = () =>”. Also, define a type if possible.

Files:

  • src/form/components/FormItem/index.tsx
⏰ 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). (4)
  • GitHub Check: build (20.x, ubuntu-latest)
  • GitHub Check: build
  • GitHub Check: build
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (1)
src/form/components/FormItem/index.tsx (1)

196-206: 启用无 addon 分支的 help 渲染,方向正确

将普通(非函数)help 交给 Form.Item 默认渲染,能修复“help 属性不生效”的核心问题,符合 PR 目标。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⭕️ bug Something isn't working form size:S This PR changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant