Skip to content

字段 widget 把渲染器专用 props 原样展开到 DOM——schema="[object Object]" 出现在真实输入框上 #3291

Description

@xuyushun441-sys

在 objectui#3222 / PR #3289 的实测中发现,未在该 PR 修复(影响面覆盖 ~80 个 widget,属独立重构)。

事实

表单渲染器渲染已注册 widget 时,stripRegisteredFieldProps 剥掉了一批渲染器专用键,但 schema 被剥掉后又显式传了回去(< RegisteredComponent schema={fieldSchema} {...registeredProps} / >,因为约 25 个 widget 读 field || schema 取配置)。

而绝大多数 widget 的写法是:

export function TextField({ value, onChange, field, readonly, ...props }: FieldWidgetComponentProps< string >) {
  const { inputType, ...domProps } = props as any;
  return < Input {...domProps}  / >;   // schema 在 domProps 里
}

schema 没被解构出来,于是原样落到 DOM 上。实测(jsdom,真表单 + 真 widget)的输出:

< input class="…" schema="[object Object]" id="_r_0_-form-item"
       aria-describedby="…" aria-invalid="true" type="text" value="" name="t" >

schema="[object Object]" 出现在每一个这样渲染的输入框上。React 不报警(全小写属性会被透传),所以它安静地存在了很久。

为什么值得修

可能的方向(需要拍板,不要直接开工)

  1. 共享的 toDomProps(props) 助手,在 @object-ui/fields 导出,每个 widget 用它替代裸 ...props 展开。显式、可 grep、可测试;但要改 ~80 个文件。
  2. 收敛 schemafield 本身(注释里说的那件事),让 schema 不再需要被传下去。更根治,但影响读 field || schema 的 ~25 个 widget。
  3. 什么都不做,只把它记录成已知取舍。

倾向 2 → 1 的顺序,但这是架构判断,应当先定方向。

边界

packages/fields(+ 可能 packages/components/src/renderers/form/)。不动 packages/spec

关联:objectui#3221(封闭该类型的那一单)、objectui#3222、PR #3289

Metadata

Metadata

Labels

bugSomething isn't workingpm:queue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions