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

Commit cc4366d

Browse files
fix(plugin-detail): record:details dedupes a titleFormat collapsed onto any field the template rendered (#10443)
Fixes #10360 Clause-②: no ## What When no declared name pointer holds a value, the record page H1 is the rendered `titleFormat`. `record:details` hides the row whose value equals that rendered string, but it compared the string only against `titleCandidates`: the two ADR-0079 resolver rungs and six literal names. A template that collapsed onto any other field was not recognised. `{contract_no} - {name}` with a blank `name` put `HT-2026-003` in the H1 and again in the "Contract No" row directly under it. The template-scan branch keeps the comparison and widens the set it compares against: 1. The candidate scan runs first, exactly as before, and a candidate match still wins. No row that was hidden before is hidden differently now. 2. Only when no candidate matches, the dedupe hides the first record field (in record key order) whose `recordDisplayValueAt` value EQUALS the rendered title AND that the template actually rendered. At most one row goes. "Actually rendered" is asked of `formatTitleTemplate` itself: blank that one field on the record, render again, and see whether the title changed. There is no second placeholder parser. objectui#8351 ruling B is kept: a row goes only on equality with the rendered string, never because a `titleFormat` exists. The declared-pointer branch (objectui#9436, landed in objectui#10358) and the empty-template walk are untouched. ## Mechanism assumptions, measured - **A1 (reuse the renderer's placeholder parser): partly falsified, route changed.** `formatTitleTemplate` exports no parser. Its placeholder regexes are inline in the function body in `@object-ui/core`'s `record-title.ts`, so reusing them literally would mean a new `@object-ui/core` export, outside this claim's file surface. Instead the renderer itself is the oracle (blank and re-render). It therefore agrees by construction on every token shape `formatTitleTemplate` accepts: `{{field}}`, whitespace inside the braces, and dotted lookup paths such as `{account.name}`, where the record field blanked is the first path segment. No regex was written. - **A2 (equality through `recordDisplayValueAt`, at most one row): confirmed. The example premise is falsified.** Two placeholders that both hold `HT-2026-003` do not collapse. Each renders its own copy, the H1 is `HT-2026-003 - HT-2026-003`, and both rows stay (pinned). Two TOP-LEVEL placeholder fields cannot both equal a collapsed title. The real two-equal case needs a dotted path. `{owner.nickname} - {rep}` with a blank nickname renders `rep`'s value, and an expanded `owner` whose display name is also `Ann` equals it too. The dedupe hides `rep`, because its placeholder rendered the H1. It keeps `owner`, because blanking `owner` leaves the title unchanged. A "first field the template names" rule would hide `owner` and keep the duplicate (pinned). If two fields both rendered the title AND both equal it, `.find` still hides only one: the first in record key order. That case needs two dotted lookups whose display names each equal the composite, so it is not pinned. - **A3 (the objectui#8351 lit controls stay true): confirmed, no retarget.** `record-details.titleFormatNoDedupe-8351.test.tsx` is unchanged and green (10/10) under the fix and under the reverse proof. - **A4 (only the template-scan branch moves): confirmed.** The change sits inside `if (interpolatedTitle)`, in the `else` that follows the declared-pointer check. The DECLARED POINTER CONTROL case pins that a template collapsing onto `contract_no` hides nothing while `nameField` holds a value. ## Tests The new `packages/plugin-detail/src/renderers/__tests__/record-details.titleFormatPlaceholderDedupe-10360.test.tsx` renders the real `page:header` beside the real body under one record context, as the objectui#9436 agreement pin does. Each case reads the H1 the user sees and then which row drops. The viewport is pinned to desktop so that `DetailSection` auto-hide cannot remove a row. - THE CARD: the H1 is `HT-2026-003`. The body has no `HT-2026-003` and no "Contract No". - COMPOSITE CONTROL: the H1 is `HT-2026-013 - Acme Corporation`, and both rows stay. - SAME VALUE IN BOTH PLACEHOLDERS: the H1 is a composite, and both rows stay. - TWO FIELDS EQUAL THE H1: `rep` goes, and the derived `name` row stays. - DECLARED POINTER CONTROL: only the pointer's row goes, and `contract_no` stays. **Red on base `c3025ead2`, before the fix.** THE CARD and TWO FIELDS EQUAL fail; the first message is `expected 'Contract NoHT-2026-003Name—Amount13' not to contain 'HT-2026-003'`. The other 3 cases pass. The H1 assertions pass on base, so the header really shows what the card says. **Reverse proof.** Run on the committed fix with `ablation-replace.mjs` in WRAP mode. Each restore was proven by blob == HEAD and an empty `git diff HEAD`. - Restoring the candidate-only comparison turns THE CARD and TWO FIELDS EQUAL red (2 failed, 16 passed). COMPOSITE, SAME VALUE, DECLARED POINTER, all 10 cases of the objectui#8351 file and all 3 of the objectui#9436 agreement file stay green. - Dropping only the "the template actually rendered it" check turns TWO FIELDS EQUAL red. The other 4 cases stay green. The subject is imported by relative path from `src`, so neither leg needed a build. ## Gates, at HEAD `84039bba8` - `pnpm exec vitest run --maxWorkers=2 packages/plugin-detail/ packages/core/src/utils/__tests__/column-identity.ratchet.test.ts packages/core/src/utils/__tests__/record-title` exited 0: 211 files (210 passed, 1 skipped), 2159 tests passed and 8 skipped. The run covers every `record-details*` suite. It also covers the source-text pins that read `record-details.tsx`: `recordDetailsInputs.spec-parity`, `detailRendererUndeclaredKeys-8649` and `column-identity.ratchet`. - The closure build `pnpm --workspace-concurrency=2 --filter "@object-ui/plugin-detail^..." build` exited 0. It built 11 packages; `test-support` has no build script. - `pnpm --filter @object-ui/plugin-detail build` exited 0. That is vite plus the dts plugin, which fails on type errors. - `pnpm --filter @object-ui/plugin-detail type-check` (`tsc --noEmit && tsc -p tsconfig.test.json`) exited 0. `--listFilesOnly` confirms that the test project includes the new file and the objectui#8351 file. - The changeset gates all exited 0: `check-changeset-presence`, `check-changeset-no-major`, `check-changeset-overwrite`, `check-changeset-fixed`, `check:changeset-claims` and `check:pending-changeset-literals`. `check:changeset-claims` is report-only. It flagged 3 pending changesets, `7997-detail-view-related-retired`, `8400-kanban-name-field-skip-set` and `8649-detail-renderer-undeclared-keys`. I read each one whole, and all three are still true against this diff. - `check:new-line-citations` (0 new), `check:control-bytes`, `check:test-path-roots` and `check:unreferenced-sources` all exited 0. - ESLint on the 2 touched TS files found 0 errors. `record-details.tsx` has 35 warnings, the same as base. The new test has 2 `no-explicit-any` warnings, from the same helper signature the objectui#9436 pin uses. The narrowing rests on three facts: - The population is the plugin-detail `lint` script, `eslint .`, under the root `eslint.config.js`. - The file count is 2, read from `--format json`. - No type-aware linting is configured (no `parserOptions.project` or `projectService`), and no custom rule in `eslint-rules/` reads other files. So this diff cannot move any untouched file's verdict. Left to CI: the full `pnpm test` shards, repo-wide `pnpm type-check`, `pnpm lint`, the `pnpm check` CLI self-check, and Build & E2E. ## Acceptance notes - **Reported to the seat for filing, not filed here (class a).** The page header and this dedupe render `titleFormat` through two different functions. The header uses `PageHeaderRenderer`'s own `interpolate` plus `cleanupTitleSeparators`; its comment records that it kept these in objectui#9436. The dedupe, `getRecordDisplayName` and `DetailView` use core's `formatTitleTemplate`. Both cases below were measured on this branch, and in each a duplicate row survives that the widened scan cannot see: - With a whitespace-only `name`, the H1 is `HT-2026-003` but core renders `HT-2026-003 -`, so the body still prints `HT-2026-003`. `getRecordDisplayName` also returns `HT-2026-003 -`. - With `{account} - {deal_no}` and an expanded `account`, the H1 is `Q3-042` but core renders `Acme - Q3-042`, so the body prints `Q3-042`. - The pending objectui#8351 changeset says the dedupe answers "whether that string is some candidate's value". That is still true of the first step. This PR's changeset, in the same release, describes the widened second step. - Whether a collapsed template should be the H1 at all is still out of scope (triage note 3). Session: `https://claude.ai/code/session_01BP8CMtACxTdLjqR6rhd33C` --- _Generated by [Claude Code](https://claude.ai/code/session_01BP8CMtACxTdLjqR6rhd33C)_ Co-authored-by: Claude <noreply@anthropic.com>
1 parent 3632060 commit cc4366d

3 files changed

Lines changed: 329 additions & 9 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
'@object-ui/plugin-detail': patch
3+
---
4+
5+
fix(plugin-detail): `record:details` no longer prints a row directly under an H1 that shows the same value when a `titleFormat` collapses onto a field outside the fixed candidate list (objectui#10360)
6+
7+
**What changed for a user.** On an object with no declared name pointer, the
8+
record page H1 is the rendered `titleFormat`. When a placeholder is blank the
9+
template collapses onto the one field that still has a value, so
10+
`"{contract_no} - {name}"` with a blank `name` renders `HT-2026-003`. The
11+
details grid used to keep the "Contract No" row, printing `HT-2026-003` again
12+
directly under the H1. That row is now hidden, as a collapsed template's row
13+
already was when the field was `name`, `title`, `subject` or another candidate.
14+
15+
**What did not change.** The comparison is the one ruled on objectui#8351
16+
(option B): a row is hidden only when its value EQUALS the rendered title, never
17+
because a `titleFormat` exists. A composite title such as
18+
`HT-2026-013 - Acme Corporation` is no field's value and still hides no row. Two
19+
placeholders holding the same value render a composite too, so both rows stay.
20+
The candidate list (the ADR-0079 resolver rungs and six literal names) is still
21+
scanned first, and a candidate that matches still wins, so no row that was
22+
hidden before is hidden differently now. The declared-pointer branch
23+
(objectui#9436) still runs first and never consults the template.
24+
25+
**How a field counts as rendered.** After the candidates, the dedupe compares
26+
the H1 against each record field whose value equals it and that the template
27+
actually rendered. "Actually rendered" is asked of `formatTitleTemplate` itself,
28+
by blanking that one field and rendering again, not of a second placeholder
29+
parser, so it agrees with the renderer on `{{…}}` placeholders, whitespace
30+
inside the braces and dotted lookup paths. A lookup whose display name happens
31+
to equal the H1, but whose dotted placeholder rendered nothing, keeps its row.
32+
At most one row is hidden.
Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
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`' H1 dedupe recognises a `titleFormat` that collapses onto
11+
* ANY field the template renders, not only onto a fixed candidate list
12+
* (objectui#10360).
13+
*
14+
* ## The defect
15+
*
16+
* When no declared name pointer holds a value, the H1 is the rendered
17+
* `titleFormat`. objectui#8351 (ruled option B) hides the row whose value
18+
* EQUALS that rendered string, and hides nothing when the string is a
19+
* composite that is no field's value. The comparison set was
20+
* `titleCandidates` alone: the two ADR-0079 resolver rungs plus six literal
21+
* names. A template that collapsed onto a field outside that list was not
22+
* recognised, so the field's row printed directly under an H1 showing the
23+
* same value. Measured by the objectui#9436 dev: no pointer,
24+
* `titleFormat: '{contract_no} - {name}'`, a blank `name` ⇒ H1 `HT-2026-003`,
25+
* and the "Contract No" row still printed `HT-2026-003`.
26+
*
27+
* ## What changed, and what did not
28+
*
29+
* The comparison is ruling B's, unchanged: `recordDisplayValueAt(field)` must
30+
* EQUAL the rendered template. Only the set of fields compared is wider. The
31+
* candidate scan runs first, exactly as before, and a candidate match still
32+
* wins. Only when no candidate matches does the scan go on to the fields the
33+
* template rendered. So no row that was hidden before is hidden differently
34+
* now; the change can only hide a row where nothing was hidden.
35+
*
36+
* "A field the template rendered" is asked of `formatTitleTemplate` itself,
37+
* never of a second placeholder parser: blank that one field on the record,
38+
* render again, and see whether the title changed. So the answer agrees with
39+
* the renderer on every token shape it accepts (`{{…}}`, inner whitespace,
40+
* dotted lookup paths). The `TWO FIELDS EQUAL THE H1` case below is why a
41+
* "which placeholders does the template name" reading is not enough.
42+
*
43+
* ## The surface under test
44+
*
45+
* Each case renders the REAL `page:header` beside the REAL body under one
46+
* record context, as `record-details.headerDedupeAgreement-9436.test.tsx`
47+
* does. It reads the H1 the user sees, then which row the body drops. A
48+
* dedupe-only pin would take the H1's value on trust.
49+
*/
50+
51+
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
52+
import { render, cleanup } from '@testing-library/react';
53+
import * as React from 'react';
54+
// Registers `page:header` (and the rest of the atoms) on the shared registry.
55+
import '@object-ui/components';
56+
import { ComponentRegistry } from '@object-ui/core';
57+
import { ActionProvider, RecordContextProvider } from '@object-ui/react';
58+
import { RecordDetailsRenderer } from '../record-details';
59+
60+
/**
61+
* The card's fixture: NO declared name pointer, so the template is the H1.
62+
* `contract_no` is on no candidate list: it is not one of the six literal
63+
* names, and the type-aware derivation lands on `name` (a name-ish exact key).
64+
*/
65+
const templateOnlySchema = {
66+
name: 'contract',
67+
label: 'Contract',
68+
titleFormat: '{contract_no} - {name}',
69+
fields: {
70+
contract_no: { type: 'text', label: 'Contract No' },
71+
name: { type: 'text', label: 'Name' },
72+
amount: { type: 'number', label: 'Amount' },
73+
},
74+
};
75+
76+
const CONTRACT_FIELDS = ['contract_no', 'name', 'amount'];
77+
78+
/**
79+
* Viewport, pinned rather than inherited, for the reason
80+
* `record-details.dedupeEmptinessTrims-8350.test.tsx` states: `DetailSection`
81+
* can also remove an EMPTY row through its auto-hide heuristic, whose
82+
* thresholds depend on the viewport. On the desktop branch no fixture here
83+
* reaches the 4-row minimum, so a row can only be missing because the dedupe
84+
* dropped it.
85+
*/
86+
const DESKTOP_WIDTH = 1280;
87+
88+
/** Render the header and the body under ONE record context; read both. */
89+
function renderPage(
90+
record: any,
91+
schema: any,
92+
fields: string[],
93+
): { h1: string | null | undefined; body: string } {
94+
const Header = ComponentRegistry.get('page:header');
95+
if (!Header) throw new Error('page:header not registered');
96+
const { container } = render(
97+
<ActionProvider>
98+
<RecordContextProvider
99+
objectName={schema.name}
100+
recordId={record.id}
101+
data={record}
102+
objectSchema={schema}
103+
>
104+
<div data-testid="page-header">
105+
<Header schema={{ type: 'page:header' }} />
106+
</div>
107+
<div data-testid="page-body">
108+
<RecordDetailsRenderer schema={{ fields } as never} />
109+
</div>
110+
</RecordContextProvider>
111+
</ActionProvider>,
112+
);
113+
const h1 = container.querySelector('[data-testid="page-header"] h1')?.textContent;
114+
const body = container.querySelector('[data-testid="page-body"]')?.textContent ?? '';
115+
return { h1, body };
116+
}
117+
118+
/** How many times `needle` occurs in `haystack`. */
119+
const occurrences = (haystack: string, needle: string): number => haystack.split(needle).length - 1;
120+
121+
beforeEach(() => {
122+
Object.defineProperty(window, 'innerWidth', { configurable: true, value: DESKTOP_WIDTH });
123+
// `useRecordEditable` probes `POST /api/v1/security/explain`; happy-dom
124+
// would resolve that to a REAL socket (objectui#6640). Its answer is
125+
// orthogonal to which heading renders and which row is hidden.
126+
vi.stubGlobal('fetch', vi.fn(async () => ({
127+
ok: true,
128+
status: 200,
129+
json: async () => ({ allowed: true }),
130+
text: async () => '{"allowed":true}',
131+
})) as never);
132+
});
133+
134+
afterEach(() => {
135+
cleanup();
136+
vi.unstubAllGlobals();
137+
});
138+
139+
describe('record:details dedupe — a `titleFormat` collapsed onto a non-candidate field (#10360)', () => {
140+
it('THE CARD — the H1 collapses onto `contract_no`, and the "Contract No" row is not printed under it', () => {
141+
// `name` is blank, so `formatTitleTemplate` drops that placeholder and its
142+
// orphan separator. The H1 reads exactly `contract_no`'s value, so that
143+
// row IS the duplicate.
144+
const { h1, body } = renderPage(
145+
{ id: 'C3', contract_no: 'HT-2026-003', name: '', amount: 13 },
146+
templateOnlySchema,
147+
CONTRACT_FIELDS,
148+
);
149+
150+
expect(h1).toBe('HT-2026-003');
151+
expect(body).not.toContain('HT-2026-003');
152+
expect(body).not.toContain('Contract No');
153+
// CONTROL: the body rendered, and the rows the H1 does not show stay.
154+
expect(body).toContain('Name');
155+
expect(body).toContain('Amount');
156+
});
157+
158+
it('COMPOSITE CONTROL — both placeholders hold a value: the H1 is no field\'s value, and no row is hidden (#8351)', () => {
159+
// The ruled option-B case, kept. A presence-only rule, or a widened scan
160+
// that stopped comparing values, would hide a row here.
161+
const { h1, body } = renderPage(
162+
{ id: 'C13', contract_no: 'HT-2026-013', name: 'Acme Corporation', amount: 14 },
163+
templateOnlySchema,
164+
CONTRACT_FIELDS,
165+
);
166+
167+
expect(h1).toBe('HT-2026-013 - Acme Corporation');
168+
expect(body).toContain('HT-2026-013');
169+
expect(body).toContain('Acme Corporation');
170+
expect(body).toContain('Amount'); // CONTROL: the body rendered at all
171+
});
172+
173+
it('SAME VALUE IN BOTH PLACEHOLDERS — the template renders a composite, so BOTH rows stay', () => {
174+
// Two placeholder fields holding the same value do not collapse: each
175+
// placeholder renders its own copy, so the H1 is the composite, which is
176+
// neither field's value. The equality test answers no for both.
177+
const { h1, body } = renderPage(
178+
{ id: 'C23', contract_no: 'HT-2026-003', name: 'HT-2026-003', amount: 15 },
179+
templateOnlySchema,
180+
CONTRACT_FIELDS,
181+
);
182+
183+
expect(h1).toBe('HT-2026-003 - HT-2026-003');
184+
expect(occurrences(body, 'HT-2026-003')).toBe(2);
185+
expect(body).toContain('Contract No');
186+
expect(body).toContain('Amount'); // CONTROL: the body rendered at all
187+
});
188+
189+
it('TWO FIELDS EQUAL THE H1 — the row the template RENDERED goes, not a field it merely names', () => {
190+
// `owner` (an expanded lookup) and `rep` both display `Ann`, and the
191+
// template names both. Only `rep` rendered the H1: `{owner.nickname}` is
192+
// blank. A scan that took the first field the template names, by
193+
// equality alone, would hide `owner` and leave `Ann` printed under the
194+
// H1. Blanking a field and rendering again is what tells the two apart:
195+
// blank `rep` and the title changes, blank `owner` and it does not.
196+
// (Two TOP-LEVEL placeholders cannot both equal the H1 this way; a
197+
// dotted path is what lets a field's own value differ from what its
198+
// placeholder rendered.)
199+
//
200+
// `rep` is on no candidate list: it is not a literal name, and the
201+
// derivation lands on `name` (a name-ish exact key) — so this case needs
202+
// the widened scan, not the candidate one.
203+
const { h1, body } = renderPage(
204+
{
205+
id: 'C33',
206+
owner: { id: 'u1', name: 'Ann', nickname: '' },
207+
rep: 'Ann',
208+
name: 'Q3 renewal',
209+
amount: 16,
210+
},
211+
{
212+
name: 'deal',
213+
label: 'Deal',
214+
titleFormat: '{owner.nickname} - {rep}',
215+
fields: {
216+
name: { type: 'text', label: 'Name' },
217+
rep: { type: 'text', label: 'Rep' },
218+
amount: { type: 'number', label: 'Amount' },
219+
},
220+
},
221+
['name', 'rep', 'amount'],
222+
);
223+
224+
expect(h1).toBe('Ann');
225+
expect(body).not.toContain('Ann');
226+
expect(body).not.toContain('Rep');
227+
// CONTROL: the body rendered, and the derived `name` row the H1 does not
228+
// show stays.
229+
expect(body).toContain('Q3 renewal');
230+
expect(body).toContain('Amount');
231+
});
232+
233+
it('DECLARED POINTER CONTROL — when the pointer holds a value, the template is never scanned (#9436)', () => {
234+
// The declared-pointer branch runs first and is untouched: the H1 is
235+
// `name`'s value and only that row goes. The template would collapse
236+
// onto `contract_no` (`code` is blank), but the header never reaches the
237+
// template, so neither may the dedupe. `contract_no` keeps its row.
238+
const { h1, body } = renderPage(
239+
{ id: 'C43', contract_no: 'HT-2026-043', code: '', name: 'Acme Corporation', amount: 17 },
240+
{
241+
...templateOnlySchema,
242+
nameField: 'name',
243+
titleFormat: '{contract_no} - {code}',
244+
},
245+
CONTRACT_FIELDS,
246+
);
247+
248+
expect(h1).toBe('Acme Corporation');
249+
expect(body).not.toContain('Acme Corporation');
250+
expect(body).toContain('HT-2026-043');
251+
expect(body).toContain('Amount'); // CONTROL: the body rendered at all
252+
});
253+
});

‎packages/plugin-detail/src/renderers/record-details.tsx‎

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,9 @@ export const RecordDetailsRenderer: React.FC<RecordDetailsRendererProps> = ({
422422
// (objectui#8351). They are NOT symmetric and only ONE is answered here:
423423
// - `objectSchema.titleFormat` — ANSWERED, below, by the ruled option B:
424424
// the template's rendered output is compared against the candidates'
425-
// values, and a composite that is no field's value hides no row.
425+
// values, then against the fields the template rendered
426+
// (objectui#10360), and a composite that is no field's value hides no
427+
// row.
426428
// - `page:header`'s own `schema.title` — NOT answered, and not answerable
427429
// from this package: it is a key on the HEADER schema, which
428430
// `record:details` never receives. Same shape, its own card.
@@ -516,13 +518,14 @@ export const RecordDetailsRenderer: React.FC<RecordDetailsRendererProps> = ({
516518
// `DetailView.resolveDisplayTitle` step 2 calls, so all three agree
517519
// about what the template produces on a given record.
518520
// - `recordDisplayValueAt` then answers the only question a dedupe has:
519-
// is that string some candidate's value?
521+
// is that string some candidate's value, or the value of a field the
522+
// template rendered (objectui#10360, see the note on the scan below)?
520523
//
521524
// Three outcomes, and the two that are NOT the ruled case are what keep this
522525
// honest:
523-
// - composite (no candidate's value equals it) → hide NOTHING. The ruled
524-
// case: "the H1 is not any single field's value, so there is no row to
525-
// hide".
526+
// - composite (no compared field's value equals it) → hide NOTHING. The
527+
// ruled case: "the H1 is not any single field's value, so there is no
528+
// row to hide".
526529
// - empty (no placeholder resolved on this record) → the header walks on
527530
// past this rung to the unified resolver, so the value-keyed walk below
528531
// runs unchanged. Suppressing on the mere PRESENCE of a `titleFormat`
@@ -547,18 +550,50 @@ export const RecordDetailsRenderer: React.FC<RecordDetailsRendererProps> = ({
547550
// the H1 is `subject`'s value. Stopping early would hide the wrong row AND
548551
// leave the real duplicate.
549552
//
553+
// ⭐ The "collapsed" outcome is matched against EVERY field the template
554+
// rendered, not only the candidates (objectui#10360). The candidates are the
555+
// resolver rungs and six literal names, so a template that collapsed onto
556+
// any other field — `{contract_no} - {name}` with a blank `name` renders
557+
// exactly `contract_no`'s value — matched none of them, and that row printed
558+
// directly under an H1 showing the same value. The comparison is ruling B's,
559+
// unchanged: equality with the rendered string, never the presence of a
560+
// template. Only the set compared is wider, and in a fixed order:
561+
// 1. the candidate scan, exactly as before, so a candidate match still
562+
// wins and no row that was hidden before moves;
563+
// 2. only then, each record field whose value equals the H1 AND that the
564+
// template actually rendered. At most one row goes (the first in record
565+
// key order), as in step 1.
566+
//
567+
// ⛔ "Actually rendered" is asked of `formatTitleTemplate` ITSELF, never of a
568+
// second placeholder parser: blank that one field, render again, and see
569+
// whether the title changed. So this agrees with the renderer on every token
570+
// shape it accepts (`{{…}}`, whitespace inside the braces, dotted lookup
571+
// paths), and cannot drift from it. It is also stricter than "a field the
572+
// template names", and that is on purpose: `{owner.nickname} - {rep}` with a
573+
// blank nickname renders `rep`'s value, and an `owner` lookup whose display
574+
// name happens to equal it is named by the template yet rendered nothing.
575+
// Hiding `owner` there would leave the real duplicate printed. Pinned in
576+
// `__tests__/record-details.titleFormatPlaceholderDedupe-10360.test.tsx`.
577+
//
550578
// The declared pointer is read through core's one exported spelling,
551579
// `declaredNameField`, exactly as `PageHeaderRenderer` reads it: the same
552580
// expression on both halves, never a re-typed `??` chain.
553581
const declaredTitleField = declaredNameField(objSchema);
554582
if (recordDisplayValueAt(data, declaredTitleField) !== undefined) {
555583
hideFieldNames.add(declaredTitleField);
556584
} else {
557-
const interpolatedTitle = formatTitleTemplate(objSchema?.titleFormat, data);
585+
const titleFormat = objSchema?.titleFormat;
586+
const interpolatedTitle = formatTitleTemplate(titleFormat, data);
558587
if (interpolatedTitle) {
559-
const shownAs = titleCandidates.find(
560-
(candidate) => recordDisplayValueAt(data, candidate) === interpolatedTitle,
561-
);
588+
const showsTitle = (field: string) =>
589+
recordDisplayValueAt(data, field) === interpolatedTitle;
590+
const shownAs =
591+
titleCandidates.find(showsTitle) ??
592+
Object.keys(data).find(
593+
(field) =>
594+
showsTitle(field) &&
595+
formatTitleTemplate(titleFormat, { ...data, [field]: undefined }) !== interpolatedTitle,
596+
);
562597
if (shownAs) hideFieldNames.add(shownAs);
563598
} else {
564599
for (const candidate of titleCandidates) {

0 commit comments

Comments
 (0)