Skip to content

Commit a60740a

Browse files
fix(components): re-measure the record header's width fold on another record (#36260)
<!-- claude-projects-attribution: {"github_login":"os-project-manager"} --> _Requested by **Leehom** · [project thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1XTRdLmK9YYgMSCJ7NH2PuUY)_ Fixes #35997 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户在记录页或抽屉里用上一条/下一条切换记录时,顶栏操作按钮会按新记录重新排布:从操作多的记录切到操作少的记录后,放得下的操作重新直接显示(最多三个),不再被多余地收进「更多」菜单。 - 属于记录页顶栏「最多显示三个操作、其余收进更多」那项改进的收尾,替经常翻记录的业务用户解决按钮莫名变少的问题。 - 出错时最坏是顶栏某个操作仍被收进「更多」菜单里(点开仍可用),不影响数据;只是界面渲染变化,可直接撤回。 - 无 ## What changes - `PageHeaderActions` (record header bar, `fitWidth`): the width cap the row's wrapping lowers is now stored with the key it was measured on, the record id from the record context plus the names of the page's own inline-eligible actions. A render whose key differs (another record, or a changed action set) draws the full budget (3, or the page's `maxVisible`), and the existing layout effect measures again, so a row that still wraps folds again one action at a time. The host-resize path (`ResizeObserver` clearing the cap) is unchanged. - The key is a string, so an equal record and action set never re-arms the fold and nothing loops: the cap is only set while the row wraps and the drawn budget is above the floor, as before. - The cap rule and the fold rule themselves (at most 3 inline, the primary never folds, host Edit never folds) are untouched. Read first, by risk: 1. `ui/packages/components/src/renderers/layout/containers.tsx` — the hunk at "A cap holds only for the record and action set it was measured on" (the key and the keyed read of the cap). 2. same file — the layout effect writing `setWidthCap({ key, cap: inline - 1 })`. 3. `ui/packages/components/src/__tests__/page-header-record-bar-35593.test.tsx` — the new top-level describe "re-measures the width fold on another record (objectstack#35997)". Two-minute verification: `pnpm --dir ui exec vitest run packages/components/src/__tests__/page-header-record-bar-35593.test.tsx` from the repo root; expect 17 passed, among them "a record with fewer actions that fit draws min(maxVisible, count) again" and its CONTROL. ## Tests - New pins in the existing shared harness for this row's width fold, as a new top-level describe (the harness file already pins the fold for the header bar, so the pins join it rather than a new file): - record A (four actions, the row wraps) folds to the primary; the host steps to record B (two actions, the row fits) by re-rendering the same tree with another record id and data: B draws both of its actions inline, i.e. min(maxVisible, count) = 2, with Edit kept. - CONTROL: the same switch where B's row still wraps folds B again to the primary (the fold still works after the reset). - Ablation (one-off, not kept): the keyed read reverted to an unkeyed one (`widthCap ? widthCap.cap : null`) through `scripts/ablation-replace.mjs`: the first pin goes red with `expected [ 'Convert', 'Edit', 'More actions' ] to include 'Log call'`, 1 failed / 16 passed; restore verified by the tool (blob equals HEAD, `git diff HEAD` empty). The test imports the renderer from source, so no build sits between the mutation and the run. ## Acceptance notes - Zone measurement: the record page and the drawers do not remount the view between records (the view's own comment on its feed key says no mount site passes a `key=`; the drawers swap `recordIdOverride`), so the row instance and its cap do survive a record switch; the defect reproduced in the new pin before the fix (the ablation leg is that reproduction). - The reset key carries the record id as well as the action names, as the card asks (record id or action list change). A switch between two records with the same action set therefore also re-measures once; that costs one extra synchronous layout pass and lands on the same fold. ## Verification Every reading below is at head `621ca521`, taken under `scripts/pm/os-verify-lock.sh` (shared box). <details><summary>Target file and package (green)</summary> - `pnpm --dir ui exec vitest run --maxWorkers=2 packages/components/src/__tests__/page-header-record-bar-35593.test.tsx`: Test Files 1 passed (1), Tests 17 passed (17). - `pnpm --dir ui exec vitest run --maxWorkers=2 packages/components/`: Test Files 503 passed, 1 skipped (504); Tests 4847 passed, 24 skipped (4871); lock VERDICT command-exit 0. - `pnpm --filter @object-ui/components run type-check` (both `tsc --noEmit` and `tsc -p tsconfig.test.json`; the test project lists the edited test file): lock VERDICT command-exit 0. - Dependency closure built first: `turbo run build --filter='@object-ui/components^...' --concurrency=2`, 48 of 48 tasks successful. </details> <details><summary>Ablation (red as expected, restored)</summary> - Mutation: the keyed read of the cap replaced by an unkeyed one, via `scripts/ablation-replace.mjs` (anchor 1 to 0, blob 4de451f to cd81ae01). - Run: 1 failed, 16 passed; the failing case is "a record with fewer actions that fit draws min(maxVisible, count) again" with `expected [ 'Convert', 'Edit', 'More actions' ] to include 'Log call'`. The CONTROL stays green under the mutation, as a control should. - Restore: blob after restore equals HEAD (4de451f), `git diff HEAD` empty. </details> <details><summary>Derived gates (dispatch-gates, 38 of 38 exit 0)</summary> - `node scripts/pm/dispatch-gates.mjs --commands` derived 38 commands for this diff; all 38 ran and exited 0, among them `check:nul-bytes`, `check:published-files`, `check:cross-package-test-inputs`, `check:test-source-alias`, `check:type-check-coverage`, `check:type-check-debt`, `check:sdui-manifest`, `check-adr-0087-registration --base origin/main`, `check-empty-changeset --base origin/main`, `check-changeset-no-major --base origin/main` and `pnpm --dir ui exec vitest run scripts/` (Test Files 172 passed, 2 skipped; Tests 5122 passed, 2 skipped). - `--ran` reconciliation: 38 derived, 38 run, 0 NOT-MEASURED, 0 UNRUN, every line carrying its exit code. - Outside the derivation: `pnpm check:changeset-fixed` exit 0 (its roster lives under `.changeset/`), and `pnpm --dir ui run check:new-line-citations`: 0 new citations. - Type-check lanes, the artifact-roster and wide-population families and the repo-wide lint are CI's. </details> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 76cb366 commit a60740a

3 files changed

Lines changed: 109 additions & 9 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@object-ui/components': patch
3+
---
4+
5+
fix(components): the record header re-measures its width fold on another record
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
In a record page's header bar the action row folds by width: while its buttons wrap past one line, the page's own actions fold into the `⋯` one at a time. The lowered budget used to come back only when the bar changed width. Stepping to another record (previous / next, or another record in the drawer) keeps the same row, so after a record with many actions a record with fewer kept the old, lower budget and folded actions that fit.
11+
12+
The lowered budget now holds only for the record and the action set it was measured on. Another record, or a changed action set, draws the full budget (3, or the page's `maxVisible`) and the next layout measures again, so a row that still does not fit folds as before. Nothing an author writes changes.

‎ui/packages/components/src/__tests__/page-header-record-bar-35593.test.tsx‎

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,3 +271,83 @@ describe('page:header in the host bar folds by width (objectstack#35853)', () =>
271271
await waitFor(() => expect(screen.getAllByRole('button').map((b) => b.textContent?.trim())).toContain('Send email'));
272272
});
273273
});
274+
275+
/**
276+
* objectstack#35997 — the width cap belongs to the record and the action set
277+
* it was measured on. The host steps between records (previous / next, the
278+
* drawer) without remounting the row, so a cap lowered on a record with many
279+
* actions must not outlive it: the next record draws the full budget and the
280+
* next layout measures again. The row's line is stubbed as above, with the
281+
* wrap point moved between the two records.
282+
*/
283+
describe('page:header in the host bar re-measures the width fold on another record (objectstack#35997)', () => {
284+
afterEach(() => vi.restoreAllMocks());
285+
286+
const onlyContacted = { visible: 'record.status == "contacted"' };
287+
const SWITCH_ACTIONS = [
288+
act('convert', 'Convert', { variant: 'primary' }),
289+
act('log_call', 'Log call'),
290+
act('send_email', 'Send email', onlyContacted),
291+
act('schedule', 'Schedule', onlyContacted),
292+
];
293+
const OTHER = { id: 'lead-2', name: 'Ada Park', status: 'new' };
294+
295+
function stubWrap() {
296+
const line = { wrapAt: 0 };
297+
vi.spyOn(HTMLElement.prototype, 'offsetTop', 'get').mockImplementation(function (this: HTMLElement) {
298+
const row = this.parentElement;
299+
if (!row || row.getAttribute('role') !== 'toolbar') return 0;
300+
return Array.from(row.children).indexOf(this) >= line.wrapAt ? 40 : 0;
301+
});
302+
return line;
303+
}
304+
305+
const tree = (record: typeof LEAD) => (
306+
<BarHost claim={vi.fn()}>
307+
<ActionProvider>
308+
<RecordContextProvider
309+
objectName="crm_lead"
310+
recordId={record.id}
311+
data={record}
312+
objectSchema={LEAD_SCHEMA}
313+
headerSystemActions={HOST_ACTIONS}
314+
>
315+
<RecordHeaderStateContext.Provider value={null}>
316+
<PageHeader schema={{ type: 'page:header', actions: SWITCH_ACTIONS }} />
317+
</RecordHeaderStateContext.Provider>
318+
</RecordContextProvider>
319+
</ActionProvider>
320+
</BarHost>
321+
);
322+
323+
it('a record with fewer actions that fit draws min(maxVisible, count) again', async () => {
324+
const line = stubWrap();
325+
line.wrapAt = 3;
326+
const { rerender } = render(tree(LEAD));
327+
const actionSlot = screen.getByTestId('action-slot');
328+
await waitFor(() => expect(inlineButtons(actionSlot)).toContain('Convert'));
329+
await waitFor(() => expect(inlineButtons(actionSlot)).not.toContain('Log call'));
330+
331+
line.wrapAt = 99;
332+
rerender(tree(OTHER));
333+
await waitFor(() => expect(inlineButtons(actionSlot)).toContain('Log call'));
334+
const labels = inlineButtons(actionSlot);
335+
expect(labels).toContain('Convert');
336+
expect(labels).toContain('Edit');
337+
expect(labels).not.toContain('Send email');
338+
});
339+
340+
it('CONTROL: a record whose row still wraps after the switch folds again', async () => {
341+
const line = stubWrap();
342+
line.wrapAt = 3;
343+
const { rerender } = render(tree(LEAD));
344+
const actionSlot = screen.getByTestId('action-slot');
345+
await waitFor(() => expect(inlineButtons(actionSlot)).not.toContain('Log call'));
346+
347+
line.wrapAt = 2;
348+
rerender(tree(OTHER));
349+
await waitFor(() => expect(inlineButtons(actionSlot)).toContain('Convert'));
350+
await waitFor(() => expect(inlineButtons(actionSlot)).not.toContain('Log call'));
351+
expect(inlineButtons(actionSlot)).toContain('Edit');
352+
});
353+
});

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

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1987,7 +1987,8 @@ export interface PageHeaderActionsProps {
19871987
* actions fold into the `⋯` one at a time, down to the primary. The record
19881988
* header's bar passes it, so a narrow drawer shows fewer than 3. The budget
19891989
* comes back when the host's bar (`[data-record-top-bar]`, else the row's
1990-
* parent) changes width. The host's buttons (Edit) still never fold.
1990+
* parent) changes width, or when the row draws another record or another
1991+
* action set (objectstack#35997). The host's buttons (Edit) still never fold.
19911992
*/
19921993
fitWidth?: boolean;
19931994
}
@@ -2027,18 +2028,19 @@ export const PageHeaderActions: React.FC<PageHeaderActionsProps> = ({
20272028
}) => {
20282029
const ctx = useRecordContext();
20292030
// objectstack#35853 — the width fold ({@link PageHeaderActionsProps.fitWidth}):
2030-
// the cap the row's wrapping has lowered the budget to, the row itself, and
2031-
// the budget the last render drew (read after it lays out).
2032-
const [widthCap, setWidthCap] = React.useState<number | null>(null);
2031+
// the cap the row's wrapping has lowered the budget to, keyed by the record
2032+
// and the action set it was measured on; the row itself; and the budget the
2033+
// last render drew with its key (read after it lays out).
2034+
const [widthCap, setWidthCap] = React.useState<{ key: string; cap: number } | null>(null);
20332035
const [fitRow, setFitRow] = React.useState<HTMLDivElement | null>(null);
2034-
const fitDrawn = React.useRef({ inline: 0, floor: 0 });
2036+
const fitDrawn = React.useRef({ inline: 0, floor: 0, key: '' });
20352037
React.useLayoutEffect(() => {
20362038
if (!fitWidth || !fitRow) return;
20372039
const items = Array.from(fitRow.children) as HTMLElement[];
20382040
if (items.length < 2) return;
20392041
const wrapped = items[items.length - 1].offsetTop > items[0].offsetTop + 1;
2040-
const { inline, floor } = fitDrawn.current;
2041-
if (wrapped && inline > floor) setWidthCap(inline - 1);
2042+
const { inline, floor, key } = fitDrawn.current;
2043+
if (wrapped && inline > floor) setWidthCap({ key, cap: inline - 1 });
20422044
});
20432045
React.useEffect(() => {
20442046
if (!fitWidth || !fitRow || typeof ResizeObserver === 'undefined') return;
@@ -2723,10 +2725,16 @@ export const PageHeaderActions: React.FC<PageHeaderActionsProps> = ({
27232725
.filter((a, i, all) => all.indexOf(a) === i)
27242726
: [];
27252727
// The width fold lowers the desktop row's budget, never below the primary.
2728+
// A cap holds only for the record and action set it was measured on: the
2729+
// host steps between records without remounting this row, so another
2730+
// record (objectstack#35997) draws the full budget and the next layout
2731+
// measures again. A string key, so an equal set never re-arms the fold.
27262732
const fitsWidth = fitWidth && !barFace && !isMobile;
2727-
const rowBudget = fitsWidth && widthCap != null ? Math.min(maxVisible, widthCap) : maxVisible;
2733+
const fitKey = JSON.stringify([ctx?.recordId, authoredButtons.map((a: any) => a?.name || a?.id)]);
2734+
const rowCap = widthCap?.key === fitKey ? widthCap.cap : null;
2735+
const rowBudget = fitsWidth && rowCap != null ? Math.min(maxVisible, rowCap) : maxVisible;
27282736
if (fitsWidth) {
2729-
fitDrawn.current = { inline: Math.min(rowBudget, authoredButtons.length), floor: authoredButtons.length > 0 ? 1 : 0 };
2737+
fitDrawn.current = { inline: Math.min(rowBudget, authoredButtons.length), floor: authoredButtons.length > 0 ? 1 : 0, key: fitKey };
27302738
}
27312739
const inlineAuthored = new Set<unknown>(authoredButtons.slice(0, rowBudget));
27322740
const inlineActions = barFace

0 commit comments

Comments
 (0)