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

Commit daf9d57

Browse files
os-justinclaude
andauthored
fix(components, plugin-detail): drop the last two primaryField reads off an object def (#8179)
`primaryField` is a `DetailViewSchema` key (`@object-ui/types` `views.ts`) — a VIEW key `DetailView.resolveDisplayTitle` reads off `schema` and is welcome to. Two consumers also read it off an OBJECT def, where nothing can declare it: `@objectstack/spec`'s object schema is a `strictObject` answering `unrecognized_keys: ['primaryField']` and `ObjectSchema.create()` throws. Measured on the shipped `@objectstack/spec@17.2.0` dist: `primaryField` in 0 files, canonical `nameField` in 68. objectstack#6326 removed the identical read from two lint rules; objectui#7287 / PR #7585 removed it from `resolveTitleField`. These two survived it, while three of this repo's own changelogs already called the probe "not a spec property — always undefined". Two different repairs, not one patch twice. `@object-ui/components` — `PageHeaderRenderer`'s record-chip chain ranked it directly under `schema.title` and ABOVE the unified ADR-0079 resolver, on the surface that renders the ACTUAL H1 of a synthesized record page. The rung is gone, so the heading comes from `titleFormat` -> the ADR-0079 resolver -> the record-key walk, the precedence `DetailView`'s own header already uses. `@object-ui/plugin-detail` — `record:details`' ladder decides WHICH ROW the body grid hides so the H1's field is not repeated under it. That is a different question from "what is the title", and `primaryField` was its first candidate. The rung is gone and the docstring, which described the header chip as resolving "from objectSchema.primaryField" and went stale when PR #7585 landed, now describes the chip as it is. User-visible on purpose: a payload carrying the off-spec key anyway gets a different H1 and a different surviving grid row. Nothing spec-legal reaches either path. `DetailViewSchema.primaryField` and the deliberate `ObjectDefLike.primaryField` declaration in `buildDefaultPageSchema` are untouched. Two fixtures spelled the key on an object def and now spell the canonical `nameField`; neither suite ever read its effect. Claude-Session: https://claude.ai/code/session_01YBWFb5YgMU5dw8p2VKj16S Co-authored-by: Claude <noreply@anthropic.com>
1 parent f6375da commit daf9d57

7 files changed

Lines changed: 392 additions & 17 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
'@object-ui/components': minor
3+
'@object-ui/plugin-detail': minor
4+
---
5+
6+
The last two consumer-side reads of `primaryField` off an OBJECT def are gone (objectui#7586).
7+
8+
`primaryField` is a `DetailViewSchema` key (`@object-ui/types` `views.ts`) — a **view** key,
9+
which `DetailView.resolveDisplayTitle` reads off `schema` and is welcome to. Read off an
10+
**object** def it is undeclared: `@objectstack/spec`'s object schema is a `strictObject`
11+
answering `unrecognized_keys: ['primaryField']`, and `ObjectSchema.create()` throws.
12+
`primaryField` appears in **zero** files of the shipped `@objectstack/spec@17.2.0` dist,
13+
against 68 for the canonical `nameField`. objectstack#6326 removed the identical read from
14+
two lint rules; objectui#7287 / PR #7585 removed it from `resolveTitleField`. These two
15+
survived it — and three of this repo's own changelogs already called the probe *"not a spec
16+
property — always undefined"* while the code kept honouring it.
17+
18+
**They are two different repairs, not one patch applied twice.**
19+
20+
`@object-ui/components` — `PageHeaderRenderer`'s record-chip chain ranked
21+
`objectSchema.primaryField` directly under `schema.title` and **above** the unified ADR-0079
22+
resolver, on the surface that renders the **actual H1** of a synthesized record page. The
23+
rung is deleted, so the heading now comes from `titleFormat` → the ADR-0079 resolver
24+
(`nameField` → `displayNameField` → type-aware derivation) → the record-key walk, the same
25+
precedence `DetailView`'s own header uses.
26+
27+
`@object-ui/plugin-detail` — `record:details`' dedupe ladder decides **which row the body
28+
grid hides**, so that the field already shown as the H1 is not repeated underneath it. That
29+
is a different question from "what is the title", and `primaryField` was its *first*
30+
candidate. The rung is deleted; the ladder is the literal display-name walk that mirrors the
31+
tail of the header chip's chain. Its docstring, which had described the chip as resolving
32+
"from objectSchema.primaryField", went stale when PR #7585 landed and now describes the chip
33+
as it is.
34+
35+
**User-visible, deliberately.** A payload that carries the off-spec key anyway changes in two
36+
ways: the H1 of its record page stops being `primaryField`'s value, and a different row
37+
survives the detail grid. Nothing spec-legal can reach either path.
38+
39+
`DetailViewSchema.primaryField` is untouched, and so is `ObjectDefLike.primaryField` in
40+
`buildDefaultPageSchema` — a deliberate declaration (not a read) that keeps an external
41+
caller's object literal type-checking.

‎apps/console/src/__tests__/record-block-record-reach.test.tsx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,10 @@ const RECORD_B = {
138138
const PROBE_OBJECT_SCHEMA = {
139139
name: PROBE_OBJECT,
140140
label: 'Probe Object',
141-
primaryField: 'name',
141+
// `nameField`, not `primaryField`: the latter is a `DetailViewSchema` key
142+
// that `@objectstack/spec`'s `strictObject` object schema refuses on an
143+
// object def, and no renderer reads it off one any more (objectui#7586).
144+
nameField: 'name',
142145
fields: [
143146
{ name: 'id', label: 'ID', type: 'text' },
144147
{ name: 'name', label: 'Name', type: 'text' },

‎packages/components/src/__tests__/page-header-title.test.tsx‎

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,125 @@ describe('PageHeaderRenderer — record title resolution', () => {
108108
expect(screen.getByText(/Audit Log abcdefgh/)).toBeTruthy();
109109
});
110110
});
111+
112+
/**
113+
* `objectSchema.primaryField` is NOT a rung of this chain (objectui#7586).
114+
*
115+
* `primaryField` is a `DetailViewSchema` key (`@object-ui/types` `views.ts`) —
116+
* a VIEW key a view author sets, which `DetailView.resolveDisplayTitle` reads
117+
* off `schema` and is welcome to. It was ALSO read here off the OBJECT def,
118+
* and ranked ABOVE the unified ADR-0079 resolver that ADR-0079 Phase 2 made
119+
* the single pointer to a record's identity.
120+
*
121+
* No producer can put it on an object: `@objectstack/spec`'s object schema is
122+
* a `strictObject` that answers `unrecognized_keys: ['primaryField']`, which
123+
* is why objectstack#6326 deleted the identical read from two lint rules and
124+
* objectui#7287 / PR #7585 deleted it from `resolveTitleField`. Three of this
125+
* repo's own changelogs already describe the probe as "not a spec property —
126+
* always undefined" while the code kept honouring it.
127+
*
128+
* ⚠️ These cases are about RANKING, not about the key being unreadable. Each
129+
* object below carries `primaryField` AND a legitimate declaration, and the
130+
* assertion is that the legitimate one wins — so deleting the rung turns them
131+
* green and re-adding it anywhere above the resolver turns them red again.
132+
* A case with `primaryField` alone would pass on a chain that had merely
133+
* demoted it, which is not what this pins.
134+
*/
135+
describe('PageHeaderRenderer — `objectSchema.primaryField` is not a rung (#7586)', () => {
136+
it('does not let `primaryField` outrank the declared `nameField`', () => {
137+
const { container } = renderHeader({
138+
objectSchema: {
139+
name: 'contract',
140+
label: 'Contract',
141+
nameField: 'contract_no',
142+
// Off-spec: a DetailViewSchema key sitting on an OBJECT def.
143+
primaryField: 'ref_no',
144+
fields: {
145+
contract_no: { type: 'text', label: 'Contract No' },
146+
ref_no: { type: 'text', label: 'Ref No' },
147+
},
148+
},
149+
record: { id: 'rec-1', contract_no: 'HT-2026-001', ref_no: 'R-999' },
150+
});
151+
152+
// The ACTUAL H1 of the synthesized record page, not a prediction of it.
153+
expect(container.querySelector('h1')?.textContent).toBe('HT-2026-001');
154+
expect(screen.queryByText('R-999')).toBeNull();
155+
});
156+
157+
it('does not let `primaryField` outrank `titleFormat`', () => {
158+
const { container } = renderHeader({
159+
objectSchema: {
160+
name: 'contact',
161+
label: 'Contact',
162+
titleFormat: '{first_name} {last_name}',
163+
primaryField: 'ref_no',
164+
fields: {
165+
first_name: { type: 'text' },
166+
last_name: { type: 'text' },
167+
ref_no: { type: 'text' },
168+
},
169+
},
170+
record: { id: 'rec-2', first_name: 'Ada', last_name: 'Lovelace', ref_no: 'R-999' },
171+
});
172+
173+
expect(container.querySelector('h1')?.textContent).toBe('Ada Lovelace');
174+
expect(screen.queryByText('R-999')).toBeNull();
175+
});
176+
177+
it('does not let `primaryField` outrank the type-aware derivation', () => {
178+
const { container } = renderHeader({
179+
objectSchema: {
180+
name: 'task',
181+
label: 'Task',
182+
// Nothing declared: the ADR-0079 resolver derives `subject` from the
183+
// field types, the rung this chain used to jump over.
184+
primaryField: 'ref_no',
185+
fields: {
186+
subject: { type: 'text', label: 'Subject' },
187+
ref_no: { type: 'text', label: 'Ref No' },
188+
},
189+
},
190+
record: { id: 'rec-3', subject: 'Fix the widget', ref_no: 'R-999' },
191+
});
192+
193+
expect(container.querySelector('h1')?.textContent).toBe('Fix the widget');
194+
expect(screen.queryByText('R-999')).toBeNull();
195+
});
196+
197+
/**
198+
* Non-vacuity for the three above, and the case that measures the DELETED
199+
* RUNG directly rather than a re-ranking of it.
200+
*
201+
* ⚠️ Written the obvious way first, and the obvious way cannot fail:
202+
* `primaryField: 'ref_no'` over a TEXT `ref_no` still produced `R-999` after
203+
* the rung was gone, because the ADR-0079 type-aware derivation picks
204+
* `ref_no` on its own — the only title-typed field on the object. Measured,
205+
* not assumed. A pin written that way would have gone green against a
206+
* `primaryField` rung that was still there.
207+
*
208+
* `autonumber` is the type that separates the two readings: it is in core's
209+
* `NON_TITLE_TYPES`, so the resolver REFUSES `ref_no` (an autonumber is a
210+
* record's number, never its name), the record-key walk below never looks at
211+
* `ref_no` either, and every remaining rung declines. Only the deleted
212+
* `primaryField` rung could put `R-999` in this heading. The chain lands on
213+
* the `${objectLabel} ${id}` floor instead.
214+
*/
215+
it('a `primaryField` the resolver refuses does not title the record at all', () => {
216+
const { container } = renderHeader({
217+
objectSchema: {
218+
name: 'ledger_entry',
219+
label: 'Ledger Entry',
220+
primaryField: 'ref_no',
221+
fields: {
222+
ref_no: { type: 'autonumber', label: 'Ref No' },
223+
posted_at: { type: 'datetime' },
224+
},
225+
},
226+
record: { id: 'abcdefgh-rest-of-id', ref_no: 'R-999', posted_at: '2026-07-04' },
227+
});
228+
229+
expect(container.querySelector('h1')?.textContent).toMatch(/^Ledger Entry abcdefgh/);
230+
expect(screen.queryByText('R-999')).toBeNull();
231+
});
232+
});

‎packages/components/src/renderers/layout/containers.tsx‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1868,11 +1868,25 @@ const PageHeaderRenderer: React.FC<any> = ({ schema, className, ...props }) => {
18681868
// 2. Author hasn't opted out via `recordChrome: false`.
18691869
// When both pass, we resolve the chip title from (in order):
18701870
// - explicit `schema.title` (interpolated against data),
1871-
// - `objectSchema.primaryField` / `titleFormat` (author overrides),
1871+
// - `objectSchema.titleFormat` (the author override),
18721872
// - the unified ADR-0079 resolver (`nameField` → `displayNameField` →
18731873
// type-aware derivation) — same precedence as DetailView's own header,
18741874
// - common display fields on the record (`name`, `title`, `display_name`),
18751875
// - `${objectLabel} ${id}` as a last-resort.
1876+
//
1877+
// ⛔ `objectSchema.primaryField` is NOT a rung and must not become one again
1878+
// (objectui#7586). It used to sit directly under `schema.title`, ABOVE the
1879+
// unified resolver — on the surface that renders the ACTUAL H1 of a
1880+
// synthesized record page, so it decided the heading a user reads. It is a
1881+
// `DetailViewSchema` key (`@object-ui/types` `views.ts`): a VIEW key, which
1882+
// `DetailView.resolveDisplayTitle` reads off `schema` and is welcome to. On
1883+
// an OBJECT def it is undeclared — `@objectstack/spec`'s object schema is a
1884+
// `strictObject` answering `unrecognized_keys: ['primaryField']` and
1885+
// `ObjectSchema.create()` throws — which is why objectstack#6326 deleted the
1886+
// identical read from two lint rules and objectui#7287 / PR #7585 deleted it
1887+
// from `resolveTitleField`. This package's own CHANGELOG already described
1888+
// the probe as "not a spec property — always undefined" while this line kept
1889+
// honouring it. Pinned in `__tests__/page-header-title.test.tsx`.
18761890
const hasRecord = !!(ctx?.data && (ctx as any)?.objectSchema);
18771891
if (hasRecord && !disableRecordChrome) {
18781892
const data: any = ctx!.data;
@@ -1882,7 +1896,6 @@ const PageHeaderRenderer: React.FC<any> = ({ schema, className, ...props }) => {
18821896
const objectLabel: string | undefined = rawObjectName
18831897
? tObjectLabel({ name: rawObjectName, label: fallbackLabel })
18841898
: fallbackLabel || undefined;
1885-
const primaryField: string | undefined = objSchema?.primaryField;
18861899
// Honor objectSchema.titleFormat (e.g. `{first_name} {last_name}`).
18871900
// Mirrors DetailView.resolveDisplayTitle's behaviour so default and
18881901
// synthesized record pages produce the same title.
@@ -1912,7 +1925,6 @@ const PageHeaderRenderer: React.FC<any> = ({ schema, className, ...props }) => {
19121925
})();
19131926
const resolvedTitle =
19141927
explicitTitle ||
1915-
(primaryField && data?.[primaryField]) ||
19161928
(interpolatedTitleFormat && !interpolatedTitleFormat.includes('{') ? interpolatedTitleFormat : '') ||
19171929
unifiedTitle ||
19181930
data?.name ||
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
/**
10+
* `record:details` no longer asks `objectSchema.primaryField` WHICH ROW to
11+
* hide (objectui#7586).
12+
*
13+
* ## The surface under test is the DEDUPE, not the title
14+
*
15+
* This renderer does not draw the H1. It draws the body grid, and drops from
16+
* it the one field whose value the page H1 is already showing — otherwise
17+
* every record page repeats itself ("客户名称: Acme Corporation" directly under
18+
* an H1 reading "Acme Corporation"). The ladder that picks that field was
19+
* topped by `objSchema?.primaryField`, so the question these cases answer is
20+
* **which row disappears**, never what the heading says. A title-only pin
21+
* passes while this ladder is still wrong, because the two are decided in
22+
* different packages: `@object-ui/components`' `PageHeaderRenderer` renders
23+
* the H1, this file renders the grid under it.
24+
*
25+
* ## Why the rung had to go
26+
*
27+
* `primaryField` is a `DetailViewSchema` key (`@object-ui/types` `views.ts`) —
28+
* a VIEW key, which `DetailView.resolveDisplayTitle` legitimately reads off
29+
* `schema`. Read off an OBJECT def it is undeclared: `@objectstack/spec`'s
30+
* object schema is a `strictObject` answering `unrecognized_keys:
31+
* ['primaryField']`, and `ObjectSchema.create()` throws. objectstack#6326
32+
* removed the identical read from two lint rules; objectui#7287 / PR #7585
33+
* removed it from `resolveTitleField`. Three of this repo's changelogs
34+
* already call the probe "not a spec property — always undefined" while the
35+
* code kept honouring it.
36+
*
37+
* ⚠️ Its removal is a real BEHAVIOUR change for a payload that carries the key
38+
* anyway — a different row survives the grid — which is why it is pinned here
39+
* rather than waved through as a dead-code deletion.
40+
*
41+
* ⚠️ The docstring this ladder carried ("the header chip resolves the title
42+
* from objectSchema.primaryField → …") went stale the moment PR #7585 landed;
43+
* it now describes the chip as it actually is.
44+
*/
45+
46+
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
47+
import { render, screen, cleanup } from '@testing-library/react';
48+
import * as React from 'react';
49+
import { RecordContextProvider } from '@object-ui/react';
50+
import { RecordDetailsRenderer } from '../record-details';
51+
52+
/**
53+
* An object whose identity field is `ref_no`, spelled the ONE way no producer
54+
* can spell it. `name` is an ordinary field here, and the two carry different
55+
* values so "which row is hidden" is answerable from the DOM alone.
56+
*/
57+
const objectSchema = {
58+
name: 'contract',
59+
label: 'Contract',
60+
primaryField: 'ref_no',
61+
fields: {
62+
ref_no: { type: 'text', label: 'Ref No' },
63+
name: { type: 'text', label: 'Name' },
64+
amount: { type: 'number', label: 'Amount' },
65+
},
66+
};
67+
68+
const FIELDS = ['ref_no', 'name', 'amount'];
69+
70+
function renderBody(record: any, schema: any = objectSchema) {
71+
return render(
72+
<RecordContextProvider
73+
objectName="contract"
74+
recordId={record.id}
75+
data={record}
76+
objectSchema={schema}
77+
>
78+
<RecordDetailsRenderer schema={{ fields: FIELDS } as never} />
79+
</RecordContextProvider>,
80+
);
81+
}
82+
83+
beforeEach(() => {
84+
// `useRecordEditable` probes `POST /api/v1/security/explain` for the
85+
// ROW-level verdict; happy-dom resolves that relative URL to a REAL socket,
86+
// which the repo's network-escape guard fails the file for (objectui#6640).
87+
// Serve it from a double — its answer is orthogonal to which row is hidden.
88+
vi.stubGlobal('fetch', vi.fn(async () => ({
89+
ok: true,
90+
status: 200,
91+
json: async () => ({ allowed: true }),
92+
text: async () => '{"allowed":true}',
93+
})) as never);
94+
});
95+
96+
afterEach(() => {
97+
cleanup();
98+
vi.unstubAllGlobals();
99+
});
100+
101+
describe('record:details dedupe — `primaryField` no longer picks the hidden row (#7586)', () => {
102+
it('hides the row the H1 actually shows, not the `primaryField` row', () => {
103+
renderBody({ id: 'C1', ref_no: 'HT-2026-001', name: 'Acme Corporation', amount: 42 });
104+
105+
// `name` is what the header chip resolves to for this record, so `name` is
106+
// the row that goes. Before this fix `primaryField` took `ref_no` out
107+
// instead, leaving the grid repeating the H1 and hiding a field nothing
108+
// else showed.
109+
expect(screen.queryByText('Acme Corporation')).toBeNull();
110+
expect(screen.getByText('HT-2026-001')).toBeInTheDocument();
111+
112+
// An ordinary row is untouched — the dedupe drops ONE field, it does not
113+
// filter the grid down.
114+
expect(screen.getByText('42')).toBeInTheDocument();
115+
});
116+
117+
it('hides nothing when `primaryField` names the only value on the record', () => {
118+
// Nothing in the literal display-name walk has a value here. Before the
119+
// fix `ref_no` was hidden and the body grid rendered a single `amount`
120+
// row; the H1 for this record is the `${objectLabel} ${id}` floor, which
121+
// no grid row duplicates, so nothing should be dropped.
122+
renderBody({ id: 'C2', ref_no: 'HT-2026-002', amount: 7 });
123+
124+
expect(screen.getByText('HT-2026-002')).toBeInTheDocument();
125+
expect(screen.getByText('7')).toBeInTheDocument();
126+
});
127+
128+
/**
129+
* CONTROL — the dedupe still runs.
130+
*
131+
* Without this, deleting the whole dedupe block would pass both cases above:
132+
* "the `ref_no` row survives" is satisfied by a renderer that hides nothing
133+
* at all. This is the case that goes red for that, and it is the reason the
134+
* two cases above are readable as a measurement of the LADDER rather than of
135+
* its absence.
136+
*/
137+
it('CONTROL: the H1 field is still dropped from the grid', () => {
138+
renderBody(
139+
{ id: 'C3', ref_no: 'HT-2026-003', name: 'Acme Corporation', amount: 42 },
140+
{ ...objectSchema, primaryField: undefined },
141+
);
142+
143+
expect(screen.queryByText('Acme Corporation')).toBeNull();
144+
expect(screen.getByText('HT-2026-003')).toBeInTheDocument();
145+
});
146+
147+
/**
148+
* CONTROL — `primaryField` on a VIEW schema is a different key and stays.
149+
*
150+
* `DetailViewSchema.primaryField` is declared (`packages/types/src/views.ts`)
151+
* and `DetailView.resolveDisplayTitle` reads it as rung 1. Nothing in this
152+
* card touches that; a change that deleted the key everywhere rather than
153+
* only where it sits on an OBJECT def turns this red.
154+
*/
155+
it('CONTROL: the declared VIEW-level `primaryField` is untouched', async () => {
156+
const { DetailView } = await import('../../DetailView');
157+
158+
render(
159+
<DetailView
160+
schema={
161+
{
162+
type: 'detail-view',
163+
objectName: 'contract',
164+
primaryField: 'ref_no',
165+
data: { id: 'C4', ref_no: 'HT-2026-004', name: 'Acme Corporation' },
166+
fields: ['name'],
167+
showHeader: true,
168+
} as never
169+
}
170+
/>,
171+
);
172+
173+
expect(screen.getByText('HT-2026-004')).toBeInTheDocument();
174+
});
175+
});

0 commit comments

Comments
 (0)