pro-components icon indicating copy to clipboard operation
pro-components copied to clipboard

🐛[BUG]V19版本EditableProTablet提示`autoFocus` supplied to `React.Fragment`报错

Open Noyaaa opened this issue 1 week ago • 4 comments

提问前先看看:

https://github.com/ryanhanwu/How-To-Ask-Questions-The-Smart-Way/blob/main/README-zh_CN.md

🐛 bug 描述

官方demo本地运行EditableProTablet就会出现 Invalid prop autoFocus supplied to React.Fragment. React.Fragment can only have key, ref, and children props.

📷 复现步骤

🏞 期望结果

💻 复现代码

© 版本信息

"@ant-design/pro-components": "^3.0.2-0",
"@ant-design/v5-patch-for-react-19": "^1.0.3",
"antd": "^6.1.0",
"next": "16.0.3",
"react": "^19.2.0",
"react-dom": "^19.2.0"

🚑 其他信息

Noyaaa avatar Dec 10 '25 16:12 Noyaaa

Hi @Noyaaa! I'm Dosu and I’m helping the pro-components team.

这是 React 19 与 EditableProTablet(@ant-design/pro-components v3.x)已知的兼容性问题:组件内部会把如 autoFocus 这样的输入相关 props 直接传递到 render/formItemRender 返回的节点,如果这些节点是 React.Fragment,React 19 会严格校验并报错,因为 Fragment 只允许 keyrefchildren 属性相关讨论

临时规避方法:

  • 自定义 render/formItemRender 时不要返回 Fragment(即不要用 <>...</><React.Fragment> 包裹),直接返回实际 DOM 元素(如 <Input /><div />)。
  • 避免给 EditableProTablet 传递 DOM 属性(如 autoFocus)到表格层级。
  • 如果必须生产用 React 19,建议暂时降级到 React 18,或关注 pro-components 后续的兼容性修复。

即使升级到最新的 antd 和 pro-components(如 2.7.11+),React 19 下仍可能出现类似警告,根本原因是 props 没有在传递到 Fragment 前做过滤源码分析

更多细节和社区反馈可参考:

建议持续关注 pro-components 的版本更新,等待官方修复。

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

dosubot[bot] avatar Dec 10 '25 16:12 dosubot[bot]

"dependencies": { "@ant-design/pro-components": "^2.8.10", "next": "16.0.8", "react": "18.0.0", "react-dom": "18.0.0" }, "devDependencies": { "@types/node": "^20", "@types/react": "^18.0.0", "@types/react-dom": "^18.0.0", "eslint": "^9", "eslint-config-next": "16.0.8", "typescript": "^5" }

react降级到18一样的还有这个问题

Noyaaa avatar Dec 11 '25 13:12 Noyaaa

这个问题在 React 18 + @ant-design/pro-components v2.8.10 下依然会出现,根本原因是 EditableProTable/ProTable 会把所有 props(包括 autoFocus 等 DOM 属性)直接透传到内部的 React.Fragment 或其它节点,但没有做过滤,导致 React.Fragment 收到非法属性时报错。这个问题不仅仅出现在 React 19,React 18 也会有,只是 React 19 校验更严格、报错更明显相关讨论和源码分析

目前没有官方修复,临时解决办法有:

  • 避免在自定义 render/formItemRender 时返回 Fragment(不要用 <>...</><React.Fragment>,直接返回实际 DOM 元素如 <Input />)。
  • 不要把 autoFocus 等 DOM 属性直接传递到 EditableProTable 层级。
  • 可以尝试升级 antd 到最新版、pro-components 到 2.7.11+,但即使如此 React 18 下依然可能有警告,只是报错方式不同社区反馈
  • 有用户反馈移除 React.StrictMode 或将 React 降级到 18.2.0(不要用 18.3.x)可以减少警告,但不是根本解决。

本质上这是 pro-components 2.x 的已知兼容性问题,建议关注后续版本修复进展。如需临时规避,建议手动过滤 autoFocus 等属性或避免 Fragment 作为渲染节点。

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

dosubot[bot] avatar Dec 11 '25 13:12 dosubot[bot]

避免 Fragment也无效,如何手动过滤EditableProTablet中的autoFocus

Noyaaa avatar Dec 11 '25 13:12 Noyaaa