Repository navigation
Commit 67c2e3a
fix(plugin-form): a form section naming a field the object lacks draws no control (#29194)
<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} -->
_Requested by **Steedos** · [project
thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbX2BpbF4EuTV9iEpP8DVMBf)_
Fixes #29021
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 改了什么:表单视图的分区里如果写了对象上不存在的字段名(拼错或字段已删除),tabbed / wizard / drawer / modal
四种布局不再为它画一个可编辑的输入框;simple 布局本来就不画。
-
为什么改:以前用户能在这个框里输入,保存时值被静默丢弃(保存只写对象声明过的字段),且因为“没改任何真实字段”,保存会把整条记录都发出去。lint
的 `form-field-unknown` 早就说这种字段“不会渲染”,现在表单与 lint 一致。
- 风险与回滚:只影响“对象 schema 已加载、且名字不在对象上、也没有 customFields 成员定义它”的分区条目;没有对象
schema 的表单(无数据源、由宿主 submitHandler 负责写入)保持原样。回滚即 revert 本 PR。
- 先看:`ui/packages/plugin-form/src/sectionFields.ts`(`fromObjectSchema` 与
`buildSectionFields`),`ui/packages/plugin-form/src/__tests__/unknownSectionField-29021.test.tsx`,`ui/packages/plugin-form/src/flatFields.ts`。
- 两分钟验证:`cd ui && pnpm exec vitest run
packages/plugin-form/src/__tests__/unknownSectionField-29021.test.tsx`,预期
8 个用例全绿(四种布局各两条)。
- 需要你做的:无,席位落地。
## What changes
`fromObjectSchema` (`ui/packages/plugin-form/src/sectionFields.ts`) used
to answer a name the object does not declare with a bare `{ name, label:
name, type: 'input' }` stub. The four arms that build a section with no
field pool (`tabbed`, `wizard`, `drawer`, `modal`) drew it as a live
text box labelled with the raw name. It now answers `undefined` when an
object schema is resolved and does not declare the name,
`normalizeSectionField` passes that through, and `buildSectionFields`
drops the entry. This is the answer the lint's `FORM_FIELD_UNKNOWN`
already gives ("silently skipped and never renders on the form") and the
one the default arm's pool and `buildFlatFields` already gave.
What is still drawn, unchanged:
- a `customFields` member naming the field (it is a whole definition);
- a self-describing inline entry carrying its own `name` (shape 3);
- a bare name on a form with NO object schema at all, such as a form
mounted without a data source whose host `submitHandler` owns the write
(`submitTargetRefusal.test.tsx`). There is no object to call the name
unknown, the lint likewise judges only a known object, and the value
does reach that host.
An authored `type` or `label` on a spec `{ field }` entry does not make
the field exist: such an entry is dropped too, as the lint reports it.
**Empty sections.** A section whose every member is unknown now builds
no field. Each arm keeps whatever it already does with an empty section;
nothing here changes that. On the default arm this is the existing
behaviour pinned by `objectFormSectionMembers-8071` row 2 (the section
is dropped whole, heading included).
**Design and preview paths.** No designer relies on the fallback.
Studio's object form designer (`StudioDesignSurface`) renders a flat
`object-form` with top-level `fields` (the `buildFlatFields` / pool
path, which already skipped unknown names). The metadata-admin view
preview (`ViewPreview`) renders the draft form view through the same
`object-form` arms, so it now shows what the record form shows; the
author's signal for the unknown name stays the lint's
`form-field-unknown`.
`fromObjectSchema` and `normalizeSectionField` now return `FormField |
undefined`. Neither is exported from the package entry (only
`sectionEntryName` is), so the public surface is unchanged.
`flatFields.ts` reads the new answer instead of its own duplicate
declaration check.
## Tests
- New
`ui/packages/plugin-form/src/__tests__/unknownSectionField-29021.test.tsx`:
for each of `tabbed`, `wizard`, `drawer`, `modal`, an EDIT form of a
real record whose section lists `title` beside `no_such_field` (bare
name) and `{ field: 'other_ghost', label: 'Other ghost' }`:
1. only `title` is drawn, no control and no label for either unknown
name (the known input with its loaded value is the non-vacuity control);
2. editing `title` and saving calls `dataSource.update('task', 't1',
payload)` with `title: 'New title'` and no key for either unknown name.
- `sectionFields.test.ts`: `normalizeSectionField` builds nothing for an
unknown name in both named shapes (also with an authored `type`); with
`objectSchema: null` the bare stub is still built (the boundary);
`buildSectionFields` drops unknown entries keeping known ones in order,
builds `[]` for an all-unknown section, and still draws a `customFields`
member and an inline entry.
- Existing rows that used an undeclared `ghost` field as a blank slate
now use a declared bare field (`sectionFields.spec-parity.test.ts`
declares `plain: { type: 'number' }`);
`selectMultipleGroupLabel.test.tsx`'s "keeps its fallback type" row now
pins that no field is built. Other call sites take `!` where the field
is declared.
## Acceptance notes
- **Ablation.** Restoring the fallback (deleting `if (ctx.objectSchema
!= null) return undefined;` through `scripts/ablation-replace.mjs`,
anchor 1 -> 0, blob restored to HEAD after) turned 7 cases red: the four
"draws only the known field" rows and three `sectionFields.test.ts`
rows. The four save rows stay green under the ablation, as expected: the
stub's value was already stripped on save before this change (the card
saw no `no_such_field` key either). They pin the save half so it cannot
regress once the box is gone.
- **The whole-record PATCH (finding, save path unchanged).** Measured in
the same harness with the fallback restored, typing `ghost` into the
stub and saving sent `{"title":"Old title","notes":"kept"}`, every drawn
field, on all four arms. That is `dirtyEditPayload` (`sanitize.ts`) by
design: the unknown key is stripped, so the diff against the loaded
record is empty, and an empty diff sends the whole payload so the save
stays a real write. With this fix the ghost box is gone, so typing into
it can no longer produce that save. A save with nothing changed still
sends every drawn field (measured: the same payload on all four arms).
That is the documented empty-diff rule, left as is per the card's
ruling.
- **Publish-time validity (finding, out of lane).** `_diagnostics` on
the metadata read door is the Zod verdict
(`packages/metadata-protocol/src/metadata-diagnostics.ts`);
`validateFormLayout`, which owns `form-field-unknown`, is wired into the
authoring-rule registry (`os validate` / `os lint`) and not into the
door, so a form view naming an unknown field still reads `valid: true`
there. That belongs to `domain:server`; nothing under `packages/**` is
touched here.
- **Dev showcase reproduction: NOT MEASURED.** It needs a full workspace
build and a dev server. The record edit route renders the form view
through `ObjectForm`'s `tabbed` arm, the same component the render pins
drive.
## Verification
All readings at head `49b88da9` (main `fea2dbb7` merged in; the 14 later
main commits touch nothing under `ui/packages/plugin-form`).
<details><summary>plugin-form suite: 218 files, 2419 tests
green</summary>
`cd ui && pnpm exec vitest run --maxWorkers=2 FILES`, under
`os-verify-lock`, in two halves of the package's 218 test files:
- first 110 files: Test Files 110 passed (110), Tests 872 passed (872),
VERDICT command-exit 0;
- last 108 files: Test Files 108 passed (108), Tests 1547 passed, 1
skipped (1548), VERDICT command-exit 0.
</details>
<details><summary>type-check and lint</summary>
- `pnpm exec turbo run type-check --concurrency=2
--filter=@object-ui/plugin-form`: Tasks 48 successful, 48 total (covers
`tsconfig.test.json`, so the test files are compiled).
- `pnpm exec eslint` on the seven touched files: exit 0, 0 errors (59
pre-existing `no-explicit-any` warnings).
</details>
<details><summary>ablation</summary>
`node scripts/ablation-replace.mjs --file
ui/packages/plugin-form/src/sectionFields.ts --anchor 'if
(ctx.objectSchema != null) return undefined;' ...` (anchor 1 -> 0, blob
d6b6782 -> 50ccedea3703), then the new render pin plus
`sectionFields.test.ts`: Test Files 2 failed (2), Tests 7 failed, 37
passed (44). Restored: blob == HEAD (d6b6782), `git diff HEAD`
empty.
</details>
<details><summary>derived gates: 34 of 34 exit 0</summary>
`node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` derived 34 commands from this diff; each ran
and exited 0, including `node scripts/check-sdui-manifest.mjs` (manifest
intact, 106 components), the changeset gates against this body, `pnpm
check:type-check-debt` (0 raw tsc errors above ledger) and `pnpm --dir
ui exec vitest run scripts/` (169 files passed, 2 skipped). `--ran`
reconciliation: 34 derived, 34 run, 0 NOT-MEASURED, 0 UNRUN.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01QsR2jTfpYE3Paxw3g66yLu)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 31670f5 commit 67c2e3a
8 files changed
Lines changed: 284 additions & 44 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
236 | 236 | | |
237 | 237 | | |
238 | 238 | | |
239 | | - | |
| 239 | + | |
240 | 240 | | |
241 | 241 | | |
242 | 242 | | |
243 | | - | |
| 243 | + | |
244 | 244 | | |
245 | 245 | | |
246 | 246 | | |
247 | 247 | | |
248 | 248 | | |
249 | 249 | | |
250 | 250 | | |
251 | | - | |
| 251 | + | |
252 | 252 | | |
253 | 253 | | |
254 | 254 | | |
255 | 255 | | |
256 | 256 | | |
257 | 257 | | |
258 | | - | |
| 258 | + | |
259 | 259 | | |
260 | 260 | | |
261 | 261 | | |
262 | 262 | | |
263 | 263 | | |
264 | | - | |
| 264 | + | |
265 | 265 | | |
266 | 266 | | |
267 | 267 | | |
268 | 268 | | |
269 | 269 | | |
270 | | - | |
271 | | - | |
| 270 | + | |
| 271 | + | |
272 | 272 | | |
273 | 273 | | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
280 | | - | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
281 | 279 | | |
282 | 280 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
62 | | - | |
63 | | - | |
| 62 | + | |
| 63 | + | |
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
84 | | - | |
85 | | - | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
86 | 89 | | |
87 | 90 | | |
88 | | - | |
| 91 | + | |
89 | 92 | | |
90 | 93 | | |
91 | 94 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | | - | |
| 79 | + | |
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
| |||
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
142 | | - | |
| 142 | + | |
143 | 143 | | |
144 | 144 | | |
145 | 145 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
54 | 59 | | |
55 | 60 | | |
56 | 61 | | |
| |||
60 | 65 | | |
61 | 66 | | |
62 | 67 | | |
63 | | - | |
64 | | - | |
| 68 | + | |
| 69 | + | |
65 | 70 | | |
66 | | - | |
| 71 | + | |
67 | 72 | | |
68 | 73 | | |
69 | 74 | | |
| |||
109 | 114 | | |
110 | 115 | | |
111 | 116 | | |
112 | | - | |
| 117 | + | |
113 | 118 | | |
114 | 119 | | |
115 | 120 | | |
| |||
0 commit comments