Skip to content
This repository was archived by the owner on Nov 4, 2026. It is now read-only.

Commit 4f74cd5

Browse files
fix(console): FormPage degrades an unregistered widget to the type renderer (objectui#10472) (#10553)
Fixes #10472 ## What changed `FormPage`'s `resolveFieldWidgetKey` took an authored `widget` whenever one was present and returned `resolveFormWidgetType(widget)`. That resolver answers a spelling nothing registers with the `text` widget, so a `select` field carrying an unknown `widget` rendered a free-text input. The spec's `FieldSchema.widget` describe (installed `@objectstack/spec@17.4.0`, read verbatim; its placeholder is spelled WIDGET here because GitHub strips angle-bracket fragments): "Form widget override — names a registered field component (resolved as `field:WIDGET`) to render this field instead of the `type` default. Degrades to the `type` renderer when unregistered." The `widget` leg now runs only when `namesRegisteredWidget(widget)` holds. Otherwise the row falls through to the arity leg and the `type` leg of the same resolver. - Files: `apps/console/src/components/FormPage.tsx` (+44 / -6), new `apps/console/src/components/FormPage.widgetDegrade-10472.test.tsx` (+135), new `.changeset/10472-formpage-widget-degrades-to-type.md` (+19, `@object-ui/console` patch). - No list of widgets was added. The lookup (H2) is `resolveFormWidgetType` itself, which is the same call the leg already made and the resolver whose loaders `getLazyFieldWidget` mounts. It is read for its documented unknown answer ("anything unknown falls back to `text`"): a spelling answered with `text` that is not itself `text` named nothing. A registered key, a retired spelling (its tombstone) and an alias the resolver knows keep resolving as before. ## Premise check (H1–H4) - H1 confirmed on `origin/main` `111fa4c`. The widget leg was `if (field.widget) return resolveFormWidgetType(field.widget);`. - Before, measured at `111fa4c` with real widgets on `/forms/:name`: `{ type: 'select', options, widget: 'no_such_widget' }` rendered `INPUT[type=text]`. `{ type: 'boolean', widget: 'no_such_widget' }` rendered `INPUT[type=text]`. - After, measured at `735c9ed` with the same probe: the select field renders `BUTTON[role=combobox]` plus the hidden `SELECT`. The boolean field renders `BUTTON[role=switch]`. `{ type: 'password', widget: 'no_such_widget' }` renders `INPUT[type=password]`. `{ type: 'select', multiple: true, widget: 'no_such_widget' }` renders the multiselect group. - Controls in the same run: `widget: 'radio'` on a select renders `radiogroup`. `widget: 'owner'` renders the tombstone. `widget: 'secret'` on a text field renders `INPUT[type=password]`. `widget: 'json'` on a text field renders the code widget's `TEXTAREA`. - H3, the record form (`packages/components/src/renderers/form/form.tsx`), was measured with the dev's probe shape and real widgets after `registerAllFields()`. It shows the same symptom, and **it is not changed here**. `select` / `field:select` with `widget: 'no_such_widget'`, and a metadata-carried `field.widget: 'no_such_widget'`, all render `INPUT[type=text]`. `field:boolean` with the same widget renders `INPUT[type=text]` too. - Why form.tsx is a different mechanism: an unregistered spelling there reaches the ruled "unregistered-widget default" branch (objectui#5322 / objectui#5375). That branch reads the spelling. Measured at `735c9ed`: `{ type: 'field:text', widget: 'secret' }` and `{ type: 'field:text', widget: 'ui:password' }` both render `INPUT[type=password]`. - A plain degrade-to-type there would hand those rows to the registered text widget. How the spec's degrade rule composes with that secret ruling is a decision, so it is reported as a finding, not guessed here. - A fix in form.tsx would also have to converge three precedence sites: `resolveWidgetType` (boolean seeding), the cascade-clear effect's own `widget || type`, and the render `resolvedType`. It would also have to update the core validator's `resolveAuthoredFieldWidgetId`, which says it mirrors that precedence. - H4: the `field:`-qualified spellings are not ones the shared resolver knows, so after this PR they degrade to the type in `FormPage`. Measured at `735c9ed`: - `widget: 'field:owner'` on a `user` field renders the person picker (`lookup-trigger`), with no refusal. Before this PR it rendered a working `INPUT[type=text]`, also with no refusal. - `widget: 'field:textarea'` renders `TEXTAREA` on a `textarea` field and `INPUT[type=text]` on a `text` field. - The record form resolves both `field:`-qualified spellings as registry keys: the tombstone for `field:owner`, and `TEXTAREA` for `field:textarea` on a text field. - The bare retired `widget: 'owner'` still reaches the tombstone in `FormPage`, and that is pinned here. That the tombstone names the row's live `type` (`data-retired-field-type="user"`) is objectui#10471, left as is. Whether a `field:`-qualified spelling is authorable on a form view at all was not measured here (the card lists it as unmeasured). ## Tests (HEAD `735c9ed`, after merging `origin/main`) - `pnpm exec vitest run apps/console/src/components/FormPage.widgetDegrade-10472.test.tsx` gave 4 passed (4) on `fb70e86`. The same 4 are inside the directory run below. - `pnpm exec vitest run apps/console/src/components/` gave Test Files 31 passed (31), Tests 407 passed (407). VITEST-EXIT=0. - `pnpm turbo run type-check --filter @object-ui/console --concurrency=2` gave Tasks 36 successful, 36 total. VERDICT command-exit 0. - `tsc --noEmit --listFiles` in `apps/console` lists the new test file (1 hit). TSC-EXIT=0. - `pnpm exec eslint` on the two changed source files reported 0 errors and 20 warnings. All 20 are outside this diff's hunks (react-refresh / no-explicit-any / set-state-in-effect, already present). - These gates all exited 0: `check:control-bytes`, `check:test-path-roots`, `check:vi-mock-specifiers`, `check:vi-mock-inherit`, `check:vi-mock-override-shape`, `check:new-line-citations` (0 new), `check:changeset-claims`, `check:pending-changeset-literals`, `check-changeset-presence.mjs` (1 changeset for 1 released package), `check-changeset-no-major.mjs`, `check:unreferenced-sources`, `check:comment-mask-corpus`, and `check-governed-queue-guard.mjs --test` (NOT GOVERNED). ## Ablation (fix committed first, mutated through `ablation-replace.mjs`, restored to HEAD with an empty `git diff HEAD`) 1. The guard was reverted to `if (field.widget) {`. Result: 2 failed | 2 passed (4). The two degrade pins went red and both controls stayed green. 2. `namesRegisteredWidget` was made to always answer false. Result: 2 failed | 2 passed (4). The registered-`radio` control and the retired-`owner` control went red, and the degrade pins stayed green. ## Acceptance notes - The pending `.changeset/10179-formpage-shared-field-resolver.md` says "An authored `widget` wins over `type`". After this PR that holds only for a widget that names something registered. This PR's changeset states the refinement, and both publish in the same release. That body was not edited because it is outside the claimed file surface. - `FormPage` still resolves alias spellings in `widget` (`json` renders code, `secret` renders password), while the record form treats them as unregistered (`json` renders `INPUT[type=text]`). Both were measured above. That difference existed before this PR and is recorded here, not decided. --- _Generated by [Claude Code](https://claude.ai/code/session_01KUxVUa7e39aNjhkKi1gsoy)_ Co-authored-by: Claude <noreply@anthropic.com>
1 parent 9cbe4db commit 4f74cd5

3 files changed

Lines changed: 198 additions & 6 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
'@object-ui/console': patch
3+
---
4+
5+
fix(console): a `FormPage` field whose `widget` names nothing registered renders its `type`, not a text box
6+
7+
The spec's `FieldSchema.widget` declares that the override names a registered
8+
field component and "Degrades to the `type` renderer when unregistered".
9+
`FormPage` took an authored `widget` whenever one was present and handed it to
10+
`resolveFormWidgetType`, which answers a spelling nothing registers with the
11+
`text` widget. So a `select` field carrying a `widget` that no widget is
12+
registered under (on the object field or on the form view) rendered a
13+
free-text input, and the user could type a value the picklist never offered.
14+
15+
The `widget` leg now asks the same shared resolver whether the spelling names
16+
anything, and falls through to the arity and `type` legs when it does not.
17+
The select renders its select. A registered widget still wins over the type, a retired spelling
18+
still reaches its tombstone, and an alias the resolver knows keeps resolving
19+
as before. No list of widgets was added: the answer is the resolver's own.

‎apps/console/src/components/FormPage.tsx‎

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,9 @@
107107
* The page shell above is this file's own; the FIELD layer is not. Each row
108108
* renders the widget the shared resolver names for it — `resolveFormWidgetType`
109109
* + `getLazyFieldWidget`, the ADR-0059 door — including the two axes a
110-
* type-keyed switch cannot see: an authored `widget` (which wins over `type`,
111-
* exactly as `form.tsx` resolves `f?.widget || f?.field?.widget || f?.type`)
110+
* type-keyed switch cannot see: an authored `widget` (which wins over `type`
111+
* when it names a registered widget, and otherwise degrades to the `type`
112+
* renderer as the spec's `FieldSchema.widget` declares — objectui#10472)
112113
* and arity (`select` + `multiple: true` is the multiselect widget). Until
113114
* #10179 a hand-rolled `switch (field.type)` stood here that knew a subset of
114115
* the declared types and rendered every other one as a text box, silently.
@@ -621,15 +622,50 @@ export function normalizeOptions(opts: unknown): Array<{ value: string; label: s
621622
});
622623
}
623624

625+
/**
626+
* What `resolveFormWidgetType` answers for a spelling nothing registers — its
627+
* documented fallback ("anything unknown falls back to `text`"). Read by
628+
* {@link namesRegisteredWidget} alone.
629+
*/
630+
const UNKNOWN_SPELLING_WIDGET = 'text';
631+
632+
/**
633+
* Does an authored `widget` spelling name a widget the shared registry holds
634+
* (objectui#10472)?
635+
*
636+
* The spec's `FieldSchema.widget` declares that the override "names a
637+
* registered field component" and "Degrades to the `type` renderer when
638+
* unregistered". The `widget` leg of {@link resolveFieldWidgetKey} used to
639+
* return `resolveFormWidgetType(widget)` unconditionally, and that resolver
640+
* answers a spelling nothing registers with its `text` fallback — so a
641+
* `select` field carrying `widget: 'no_such_widget'` rendered a free-text box
642+
* instead of its select.
643+
*
644+
* ⛔ No list of widgets lives here. The question goes to the SAME resolver the
645+
* row renders through (`getLazyFieldWidget` mounts what it names), and is read
646+
* for that one documented answer: a spelling it answers with `text`, when the
647+
* author did not write `text`, named nothing. Everything else it knows keeps
648+
* resolving as before — a registered key, a retired spelling (whose tombstone
649+
* still refuses visibly) and an alias of a registered key (`secret` →
650+
* `password`).
651+
*/
652+
function namesRegisteredWidget(widget: string): boolean {
653+
return resolveFormWidgetType(widget) !== UNKNOWN_SPELLING_WIDGET || widget === UNKNOWN_SPELLING_WIDGET;
654+
}
655+
624656
/**
625657
* The registered widget key a row renders (objectui#10179, objectui#10177).
626658
*
627659
* ⛔ No mapping lives here. Every step is the shared chain's own answer, in the
628660
* order the sibling renderer applies them:
629661
*
630-
* 1. an authored `widget` wins over `type` outright, un-arity'd — `form.tsx`
631-
* resolves `f?.widget || f?.field?.widget || f?.type`, where only the
632-
* `type` leg was produced by `mapFieldTypeToFormType(type, { multiple })`;
662+
* 1. an authored `widget` that names a REGISTERED widget wins over `type`
663+
* outright, un-arity'd — `form.tsx` resolves
664+
* `f?.widget || f?.field?.widget || f?.type`, where only the `type` leg was
665+
* produced by `mapFieldTypeToFormType(type, { multiple })`. One that names
666+
* nothing takes the next two steps instead (objectui#10472), because the
667+
* spec's `FieldSchema.widget` declares that it "Degrades to the `type`
668+
* renderer when unregistered" — see {@link namesRegisteredWidget};
633669
* 2. otherwise ARITY: `mapFieldTypeToFormType` is asked for the multi-value
634670
* answer, and it is taken only where the shared table says the arity MOVES
635671
* the widget (`select` + `multiple` → `multiselect`). Every other
@@ -646,7 +682,9 @@ function resolveFieldWidgetKey(field: {
646682
widget?: string;
647683
multiple?: boolean;
648684
}): string {
649-
if (field.widget) return resolveFormWidgetType(field.widget);
685+
if (field.widget && namesRegisteredWidget(field.widget)) {
686+
return resolveFormWidgetType(field.widget);
687+
}
650688
if (field.multiple) {
651689
const multi = mapFieldTypeToFormType(field.type, { multiple: true });
652690
if (multi !== mapFieldTypeToFormType(field.type)) {
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* objectui#10472 — an authored `widget` that names nothing registered degrades
5+
* to the field's `type` renderer, and a registered one still wins over `type`.
6+
*
7+
* ## The contract
8+
*
9+
* The spec's `FieldSchema.widget` describe: "Form widget override — names a
10+
* registered field component (resolved as `field:<widget>`) to render this
11+
* field instead of the `type` default. Degrades to the `type` renderer when
12+
* unregistered."
13+
*
14+
* ## The defect
15+
*
16+
* The `widget` leg of `resolveFieldWidgetKey` returned
17+
* `resolveFormWidgetType(field.widget)` whenever a `widget` was present, and
18+
* that resolver answers a spelling nothing registers with `text`. So a `select`
19+
* field carrying `widget: 'no_such_widget'` rendered a free-text input, where
20+
* the contract says it renders its select.
21+
*
22+
* ## How it is observed
23+
*
24+
* Real widgets, not stubs: the question is what the page puts on screen, and a
25+
* stubbed `getLazyFieldWidget` would answer it by construction. Each control is
26+
* found by ROLE and by the row's visible label, so the same query also proves
27+
* the label reaches the control the row really renders (the label association
28+
* reads the same resolver).
29+
*
30+
* The lit control is the other half of the rule: a REGISTERED widget
31+
* (`radio`) on the same `select` field still beats the type. Without it, a
32+
* change that ignored `widget` altogether would pass the degrade pins.
33+
*/
34+
35+
import { describe, expect, it, vi, afterEach } from 'vitest';
36+
import { render, screen, cleanup } from '@testing-library/react';
37+
import { MemoryRouter, Route, Routes } from 'react-router-dom';
38+
import { FormPage } from './FormPage';
39+
40+
vi.mock('sonner', () => ({ toast: { success: vi.fn(), error: vi.fn() } }));
41+
42+
const OPTIONS = [
43+
{ value: 'new', label: 'New' },
44+
{ value: 'won', label: 'Won' },
45+
];
46+
47+
/** A spelling no widget is registered under. */
48+
const UNREGISTERED = 'no_such_widget';
49+
50+
/** Render the internal route over one object schema and one field list. */
51+
function renderForm(objectFields: Record<string, unknown>, viewFields: unknown[]) {
52+
const routes: Array<{ match: string; body: unknown }> = [
53+
{
54+
match: '/meta/view/',
55+
body: {
56+
name: 'probe.form',
57+
object: 'probe',
58+
viewKind: 'form',
59+
label: 'Probe',
60+
config: { type: 'simple', sections: [{ label: 'Probe', fields: viewFields }] },
61+
},
62+
},
63+
{ match: '/meta/object/', body: { name: 'probe', label: 'Probe', fields: objectFields } },
64+
];
65+
vi.stubGlobal(
66+
'fetch',
67+
vi.fn(async (url: string) => {
68+
const route = routes.find((r) => String(url).includes(r.match));
69+
if (!route) throw new Error(`unstubbed fetch: ${url}`);
70+
return {
71+
ok: true,
72+
status: 200,
73+
statusText: 'OK',
74+
json: async () => route.body,
75+
text: async () => JSON.stringify(route.body),
76+
} as unknown as Response;
77+
}),
78+
);
79+
return render(
80+
<MemoryRouter initialEntries={['/forms/probe.form']}>
81+
<Routes>
82+
<Route path="/forms/:name" element={<FormPage mode="internal" />} />
83+
</Routes>
84+
</MemoryRouter>,
85+
);
86+
}
87+
88+
afterEach(() => {
89+
cleanup();
90+
vi.unstubAllGlobals();
91+
vi.restoreAllMocks();
92+
});
93+
94+
describe('objectui#10472 — an unregistered `widget` degrades to the `type` renderer', () => {
95+
it('renders the select for a `select` OBJECT field whose `widget` names nothing', async () => {
96+
renderForm({ stage: { type: 'select', label: 'Stage', options: OPTIONS, widget: UNREGISTERED } }, ['stage']);
97+
expect(await screen.findByRole('combobox', { name: 'Stage' })).toBeInTheDocument();
98+
expect(screen.queryByRole('textbox', { name: 'Stage' })).toBeNull();
99+
});
100+
101+
it('renders the select for a FORM-VIEW field whose `widget` names nothing', async () => {
102+
renderForm(
103+
{ stage: { type: 'select', label: 'Stage', options: OPTIONS } },
104+
[{ field: 'stage', widget: UNREGISTERED }],
105+
);
106+
expect(await screen.findByRole('combobox', { name: 'Stage' })).toBeInTheDocument();
107+
expect(screen.queryByRole('textbox', { name: 'Stage' })).toBeNull();
108+
});
109+
110+
it('CONTROL — a REGISTERED `widget` still wins over the type: `radio` on the same select field', async () => {
111+
renderForm({ stage: { type: 'select', label: 'Stage', options: OPTIONS, widget: 'radio' } }, ['stage']);
112+
expect(await screen.findByRole('radiogroup', { name: 'Stage' })).toBeInTheDocument();
113+
expect(screen.queryByRole('combobox', { name: 'Stage' })).toBeNull();
114+
expect(screen.queryByRole('textbox', { name: 'Stage' })).toBeNull();
115+
});
116+
117+
it('CONTROL — a RETIRED `widget` spelling is not "unregistered": `owner` still reaches its tombstone', async () => {
118+
// The tombstone reports the retirement on the console; that report is not
119+
// what this file judges. Nor is WHICH spelling the tombstone names — only
120+
// that the refusal renders instead of the type's live picker.
121+
vi.spyOn(console, 'error').mockImplementation(() => {});
122+
renderForm(
123+
{
124+
who: { type: 'user', label: 'Who', widget: 'owner' },
125+
live: { type: 'text', label: 'Live' },
126+
},
127+
['who', 'live'],
128+
);
129+
// The live row's widget is lazy. Once it is on screen, every row is.
130+
await screen.findByRole('textbox', { name: 'Live' });
131+
const row = screen.getByText('Who', { selector: 'label' }).parentElement!;
132+
expect(row.querySelector('[data-testid="field-retired-tombstone"]')).not.toBeNull();
133+
expect(row.querySelectorAll('input, button, [role="combobox"]')).toHaveLength(0);
134+
});
135+
});

0 commit comments

Comments
 (0)