Skip to content

TextAreaField 读取的 mobileFullscreen prop 全仓无人生产,注释却说"宿主表单传入" #3232

Description

@os-zhuang

在 objectui#3221(给 FieldWidgetComponentProps 去掉 [key: string]: any)时发现,不在该 PR 修

现象

packages/fields/src/widgets/TextAreaField.tsx 的文档注释声称:

Mobile UX (round 3): when the host form passes mobileFullscreen (or the field schema sets mobile_fullscreen: true), an "expand" affordance opens a fullscreen edit dialog

实现读了四条来源:

const showFullscreenButton = Boolean(
  (props as any).mobileFullscreen ??      // ① camelCase prop
  textareaField?.mobile_fullscreen ??     // ② 字段元数据
  (props as any).mobile_fullscreen ??     // ③ snake_case prop
  (props as any).schema?.mobile_fullscreen, // ④ schema 载体
);

全仓 grep 之后:

  • mobileFullscreen(camelCase)没有任何生产者。 唯一出现该拼写的地方就是 TextAreaField 自己(读取处 + 第 57 行的解构剥离)。注释里的"宿主表单传入"从未成立。
  • mobile_fullscreen 作为 prop 也到不了:form.tsxstripRegisteredFieldProps() 明确把 mobile_fullscreenfullscreen 从转发给已注册 widget 的 props 里剔除(第 266-267 行)。
  • 真正活着的只有 (以及 ④,在表单路径下与 ② 指向同一个对象)。生产者是 packages/plugin-form/src/ObjectForm.tsx:1049:{ ...f, mobile_fullscreen: true },写在字段元数据上。

后果

不是运行时 bug(功能经 ② 正常工作),而是三个可维护性问题:

  1. 注释描述了一条不存在的契约,下一个作者会照着它去传一个被静默忽略的 prop;
  2. 三条死读取路径,其中 ③ 被上游明确剥离 —— 属于「消费者侧宽容」正在固化第二套事实契约(AGENTS.md #0.1);
  3. mobileFullscreen / mobile_fullscreen 两种拼写并存,恰好是主令 [WIP] Enhance UI components for forms and layouts #12 说的那种应该在生产者收敛、而不是在消费者用 ?? 累积的情况。

建议

保留 ②(元数据是唯一真实生产者),删除 ①③④,并把注释改成描述真实来源。如果确实需要「宿主强制全屏」的 prop 覆盖能力,那就明确声明一个键并让某个宿主真的传它 —— 而不是三个拼写都读、都没人写。

为什么现在才能看见

FieldWidgetComponentProps 当时以 [key: string]: any 结尾,(props as any).mobileFullscreen 是完全合法的读取,类型 any,运行时恒 undefined。objectui#3221 收紧类型后,这类「读了但没人写」的键才可能被追问。

关联:objectui#3221、objectui#3161。

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions