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

🐛[BUG]protable 的lightfilter模式下select组件清除会提示:Cannot read properties of null (reading 'label')

Open birdycn opened this issue 4 months ago • 6 comments

        {
          title: intl.formatMessage({ id: 'field.type' }),
          dataIndex: 'type',
          key: 'type',
          width: 40,
          ellipsis: true,
          valueEnum: { to: {
    text: intl.formatMessage({ id: 'field.address.type.to' }),
    color: 'success',
  },
  cc: {
    text: intl.formatMessage({ id: 'field.address.type.cc' }),
    color: 'blue',
  },
  bcc: {
    text: intl.formatMessage({ id: 'field.address.type.bcc' }),
    color: 'purple',
  },},
        },

点击清除按钮会报错,跟国际化无关,试过把所有column删了,只留下一句{xx:{text:xx,color:'green'}}一样报错

Cannot read properties of null (reading 'label')

birdycn avatar Aug 09 '25 07:08 birdycn

TypeError: Cannot read properties of null (reading 'label') at getValueOrLabel (mf-dep____vendor.044e73ab.js:67196:71) at LightSelect (mf-dep____vendor.044e73ab.js:67286:8) at renderWithHooks (mf-dep____vendor.044e73ab.js:317022:18) at updateForwardRef (mf-dep____vendor.044e73ab.js:320776:20) at beginWork (mf-dep____vendor.044e73ab.js:323206:16) at beginWork$1 (mf-dep____vendor.044e73ab.js:328996:14) at performUnitOfWork (mf-dep____vendor.044e73ab.js:328127:12) at workLoopSync (mf-dep____vendor.044e73ab.js:328036:5) at renderRootSync (mf-dep____vendor.044e73ab.js:328004:7) at recoverFromConcurrentError (mf-dep____vendor.044e73ab.js:327420:20) at performSyncWorkOnRoot (mf-dep____vendor.044e73ab.js:327666:20) at flushSyncCallbacks (mf-dep____vendor.044e73ab.js:313578:22)

birdycn avatar Aug 09 '25 07:08 birdycn

这个报错的根本原因是 LightFilter 模式下,Select 组件在清除时会传递 null,导致内部的 getValueOrLabel 方法没有做 null 判断,直接读取 label 属性,从而抛出异常。这是 LightFilter 和 Select 组件交互时的已知 bug,并且和国际化无关,和 valueEnum 的结构也无关,只要清除就会触发。

近期 pro-components 已经合并了相关修复(比如 #9158#9162),对 Select 选项的 label/value 处理和空值安全性做了优化,升级到最新版本即可解决此问题。

如果暂时无法升级,可以考虑不用 LightFilter,或者保证 options 数据始终存在且结构完整,但本质上还是需要等官方修复。相关 issue 讨论和复现可以参考 #8410#8152#7225

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

dosubot[bot] avatar Aug 09 '25 07:08 dosubot[bot]

更新到2.8.10了还是不行

birdycn avatar Aug 09 '25 07:08 birdycn

这个 bug 在 2.8.10 版本里还没有修复,相关修复(#9158#9162)是在 2025 年 7 月合并的,2.8.10 还没包含这些改动。建议升级到包含这些 PR 的最新版本才能彻底解决。如果暂时无法升级,目前没有官方的完整解决办法,只能考虑不用 LightFilter 或自行在本地打补丁(比如在 getValueOrLabel 里加 null 判断)相关讨论参考。如果需要临时的代码修复方案,可以告知我。

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

dosubot[bot] avatar Aug 09 '25 07:08 dosubot[bot]

更新到3.0.1-0后

Something went wrong. antd_lib_table_hooks_useLazyKVMap__WEBPACK_IMPORTED_MODULE_21__ is not a function

birdycn avatar Aug 09 '25 07:08 birdycn

这个报错的根本原因是 pro-components 3.x 依赖了 antd 的深层导入(如 antd/lib/table/hooks/useLazyKVMap),但从 antd 5.0.0 开始,官方已经移除了 lib 和 es 目录的深层导入支持,所有 API 只能通过主入口导入。这会导致 pro-components 3.x 在 antd 5.x 环境下运行时报 “is not a function” 的错误,因为相关模块根本没有被正确导出或打包参考

目前没有官方的兼容补丁或迁移文档,建议:

  1. 检查你的 antd 版本。如果是 antd 5.x,建议临时降级到 antd 4.x,保证和 pro-components 3.x 的深层导入兼容。
  2. 如果必须用 antd 5.x,只能等待 pro-components 后续版本适配,或者自行尝试 patch pro-components 里的相关导入(风险较高,不推荐)。

如果能提供下你当前的 antd 版本,可以帮你进一步确认兼容性和给出具体建议。

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

dosubot[bot] avatar Aug 09 '25 07:08 dosubot[bot]