diff --git a/.changeset/35941-owner-once-body.md b/.changeset/35941-owner-once-body.md new file mode 100644 index 00000000000..0a00be20e16 --- /dev/null +++ b/.changeset/35941-owner-once-body.md @@ -0,0 +1,14 @@ +--- +'@object-ui/plugin-detail': patch +--- + +fix(plugin-detail): the record page names the owner once when a details section already shows the owner field + +Clause-②: no +Metadata-protocol: none + +On the default record page, the meta line at the foot of the details column (created · updated · owner · id) always named the record's owner, and a details section usually showed the `owner_id` field as well: in a declared field group, in the "Other" group that collects fields no declared group takes, or in the derived section of an object that declares no groups. So the owner was shown twice. The meta line already left the owner out when the highlight strip showed it, and the default page no longer draws a strip, so that rule never applied. + +The meta line now also leaves the owner out when a details section of the page's own record draws the `owner_id` row. The owner then shows once, as the section's field, where it can also be changed. The sections report the rows they actually draw, so the owner stays on the meta line whenever no section draws it: the field is hidden, the reader may not read it, a `visibleWhen` hides it or its group, or its section is collapsed. When a collapsed section holding it is opened, the owner moves from the meta line to that section. The field groups are drawn as declared. The highlight strip rule is unchanged. + +This changes the laid-out default record page, the one `RecordPageColumns` draws. A default page whose tab strip cannot be laid out keeps the strip-only rule. No metadata key, value or default changes, and no prop, export or locale key is added. diff --git a/ui/packages/app-shell/src/views/RecordDetailView.phoneOwnerLine-28909.test.tsx b/ui/packages/app-shell/src/views/RecordDetailView.phoneOwnerLine-28909.test.tsx index f0f85dbbb9f..ae786e42763 100644 --- a/ui/packages/app-shell/src/views/RecordDetailView.phoneOwnerLine-28909.test.tsx +++ b/ui/packages/app-shell/src/views/RecordDetailView.phoneOwnerLine-28909.test.tsx @@ -15,8 +15,19 @@ * - until objectstack#35891 the phone header drew four highlights (the * owner past them, so the meta line named it) and the desktop strip all * five (the strip named the owner, the meta line did not); - * - the default page draws no strip now, so at 390 px and at 1440 px the - * meta line names the owner. + * - the default page draws no strip now, and the body's details sections + * draw `owner_id` (here in the auto-derived section, the object declaring + * no field groups). + * + * objectstack#35941 supersedes the pin this file held, "no strip, and the meta + * line names the owner": the maintainer's ruling (card comment 7056427422, + * option A, 「底部行不再显示」) is that when the body renders `owner_id` the + * meta line leaves the owner out, so the owner appears once, as the body + * field. #28909's intent is unchanged: the owner is on the page at every + * width, exactly once. Both halves are pinned at 390 px and at 1440 px: the + * body draws the owner (the meta line does not), and an object whose body + * draws no `owner_id` (the field is `hidden`) keeps the owner on the meta + * line. */ import * as React from 'react'; @@ -124,14 +135,22 @@ function metadataFor(objects: unknown[]) { } as never; } -function mountPage() { +/** The same lead whose body draws no `owner_id`: the field is hidden. */ +const OBJECTS_OWNER_HIDDEN = [ + { + ...OBJECTS[0], + fields: { ...OBJECTS[0].fields, owner_id: { ...OBJECTS[0].fields.owner_id, hidden: true } }, + }, +]; + +function mountPage(objects: unknown[] = OBJECTS) { render( - + {}} />} + element={ {}} />} /> @@ -154,6 +173,8 @@ async function metaLineLoaded(): Promise { } const ownerEntry = (metaLine: HTMLElement) => metaLine.querySelector('[data-record-meta-owner]'); +/** How many times the owner's name is painted on the whole page. */ +const ownerCount = () => document.body.textContent!.split('Ada Admin').length - 1; beforeEach(() => { cleanup(); @@ -182,19 +203,36 @@ describe('the owner at every width, once (objectstack#28909)', () => { // Until objectstack#35891 the default page drew a strip of the declared // highlights: four on a phone (the owner past them, so the meta line named // it) and all five on a desktop (the strip named the owner, the meta line - // did not). The default page draws no strip now, at any width, so the meta - // line names the owner at both. + // did not). The default page draws no strip now, at any width. The body + // draws `owner_id`, so the owner is that field and the meta line leaves it + // out (objectstack#35941, ruling 7056427422). it.each([ ['a phone', 390], ['a desktop', 1440], - ])('on %s: no strip, and the meta line names the owner', async (_face, width) => { + ])('on %s: no strip, the body draws the owner, and the meta line does not', async (_face, width) => { setWidth(width); mountPage(); const metaLine = await metaLineLoaded(); expect(document.querySelector('[data-highlights-face]')).toBeNull(); + await waitFor(() => expect(ownerCount()).toBe(1)); + expect(ownerEntry(metaLine)).toBeNull(); + expect(metaLine.textContent).not.toContain('Ada Admin'); + // The rest of the meta line is still drawn. + expect(metaLine.querySelector('[data-record-meta-id]')!.textContent).toBe('r-1'); + }); + + it.each([ + ['a phone', 390], + ['a desktop', 1440], + ])('on %s: a body that draws no owner_id keeps the owner on the meta line', async (_face, width) => { + setWidth(width); + mountPage(OBJECTS_OWNER_HIDDEN); + const metaLine = await metaLineLoaded(); + expect(document.querySelector('[data-highlights-face]')).toBeNull(); const owner = ownerEntry(metaLine); expect(owner).toBeTruthy(); expect(owner!.textContent).toContain('Ada Admin'); + expect(ownerCount()).toBe(1); // The rest of the meta line is still drawn. expect(metaLine.querySelector('[data-record-meta-id]')!.textContent).toBe('r-1'); }); diff --git a/ui/packages/app-shell/src/views/RecordMetaFooter.ownerOnceBody-35941.test.tsx b/ui/packages/app-shell/src/views/RecordMetaFooter.ownerOnceBody-35941.test.tsx new file mode 100644 index 00000000000..a4da599c909 --- /dev/null +++ b/ui/packages/app-shell/src/views/RecordMetaFooter.ownerOnceBody-35941.test.tsx @@ -0,0 +1,216 @@ +/** + * ObjectUI + * Copyright (c) 2024-present ObjectStack Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +/** + * objectstack#35941 — the record page names the owner ONCE when its body draws + * `owner_id`. + * + * The maintainer's ruling (7056427422, option A): when a field group on the + * record page renders `owner_id`, the bottom meta line leaves the owner out, + * so the owner appears once, as the body field, where it can be changed; when + * no group renders it, the meta line shows the owner as before; the body's + * groups stay as declared. + * + * The page is composed here the way `RecordDetailView` composes the default + * page: the sections from `deriveRecordDetailSections` (the declared groups, + * the "Other" bucket, or the auto split), the page from + * `buildDefaultPageSchema`, its columns from `buildDefaultPageColumns`, and + * `RecordPageColumns` drawing the real `record:details` block with the + * `RecordMetaFooter` closing the details column. So "the body draws the owner" + * is read from the sections the block actually mounts, and the owner is + * counted over the whole page. + * + * The strip half of the rule (a highlight strip that draws the owner) is + * pinned in `@object-ui/plugin-detail`'s `RecordMetaFooter.ownerOnce-28868` + * and `RecordMetaFooter.drawnStrip-28909`, unchanged. + */ + +import * as React from 'react'; +import { describe, it, expect, beforeAll, beforeEach, afterEach, vi } from 'vitest'; +import { render, cleanup, fireEvent, within } from '@testing-library/react'; +import { RecordContextProvider } from '@object-ui/react'; +// Module scope, so the registry's cold transform lands in the import phase. +import { + RecordMetaFooter, + RecordPageColumns, + buildDefaultPageColumns, + buildDefaultPageSchema, +} from '@object-ui/plugin-detail'; +import { deriveRecordDetailSections } from './recordDetailSections'; + +const OBJECT = 'os_35941_contact'; +const OWNER_NAME = 'Ada Owner'; + +/** Distinct values, so every value is read off the page by what it paints. */ +const RECORD = { + id: 'C-35941', + name: 'Grace Hopper', + email: 'grace@example.com', + phone: 'phone-value', + owner_id: { id: 'u-ada', name: OWNER_NAME }, + created_at: '2026-10-16T00:00:00.000Z', + updated_at: '2026-10-18T00:00:00.000Z', +}; + +const FIELDS = { + name: { type: 'text', label: 'Name' }, + email: { type: 'email', label: 'Email' }, + phone: { type: 'text', label: 'Phone' }, + owner_id: { type: 'lookup', label: 'Owner', reference: 'sys_user' }, +}; + +type ObjectDef = { name: string; fields: Record>; fieldGroups?: unknown[] }; + +/** The default record page of `objectDef`, laid out wide, with its meta line. */ +function renderDefaultPage(objectDef: ObjectDef) { + const sections = deriveRecordDetailSections(objectDef, { moreDetails: 'More details', ungrouped: 'Other' }); + type SynthOptions = NonNullable[1]>; + const page = buildDefaultPageSchema(objectDef as Parameters[0], { + sections: sections as SynthOptions['sections'], + }); + const columns = buildDefaultPageColumns(page); + expect(columns, 'the default page must lay out into columns').not.toBeNull(); + const dataSource = { getObjectSchema: async () => objectDef }; + return render( + + } + /> + , + ); +} + +const footerOf = (container: HTMLElement) => + container.querySelector('[data-testid="record-meta-footer"]') as HTMLElement | null; +const footerOwner = (container: HTMLElement) => footerOf(container)?.querySelector('[data-record-meta-owner]') ?? null; +const detailsColumn = (container: HTMLElement) => + container.querySelector('[data-record-column="details"]') as HTMLElement; +/** How many times the owner's name is painted on the whole page. */ +const ownerCount = (container: HTMLElement) => container.textContent!.split(OWNER_NAME).length - 1; + +beforeAll(() => Object.defineProperty(window, 'innerWidth', { configurable: true, value: 1280 })); + +beforeEach(() => { + // `useRecordEditable` asks the explain endpoint; its answer is orthogonal to + // which fields the body draws, so a double answers it. + vi.stubGlobal('fetch', vi.fn(async () => ({ + ok: true, + status: 200, + json: async () => ({ allowed: true }), + text: async () => '{"allowed":true}', + })) as never); +}); + +afterEach(() => { + cleanup(); + vi.unstubAllGlobals(); +}); + +describe('the body draws owner_id: the meta line leaves the owner out (objectstack#35941)', () => { + it('a declared group holding owner_id: the owner is painted once, in the body', () => { + const { container } = renderDefaultPage({ + name: OBJECT, + fieldGroups: [ + { key: 'basics', label: 'Basics' }, + { key: 'ownership', label: 'Ownership' }, + ], + fields: { + name: { ...FIELDS.name, group: 'basics' }, + email: { ...FIELDS.email, group: 'basics' }, + phone: { ...FIELDS.phone, group: 'basics' }, + owner_id: { ...FIELDS.owner_id, group: 'ownership' }, + }, + }); + // Live control: the body and the meta line both drew. + expect(within(detailsColumn(container)).getByText('grace@example.com')).toBeTruthy(); + expect(footerOf(container)!.querySelector('[data-record-meta-id]')!.textContent).toBe('C-35941'); + + expect(footerOwner(container)).toBeNull(); + expect(ownerCount(container)).toBe(1); + // The group stays as declared: its heading and the owner row are there. + expect(within(detailsColumn(container)).getByText('Ownership')).toBeTruthy(); + expect(footerOf(container)!.textContent).not.toContain(OWNER_NAME); + }); + + it('no declared groups: owner_id lands in the auto-derived section, and is painted once', () => { + const { container } = renderDefaultPage({ name: OBJECT, fields: FIELDS }); + expect(within(detailsColumn(container)).getByText('grace@example.com')).toBeTruthy(); + expect(footerOf(container)).not.toBeNull(); + + expect(footerOwner(container)).toBeNull(); + expect(ownerCount(container)).toBe(1); + }); + + it('declared groups that leave owner_id out: it lands in the "Other" bucket, and is painted once', () => { + const { container } = renderDefaultPage({ + name: OBJECT, + fieldGroups: [{ key: 'basics', label: 'Basics' }], + fields: { + name: { ...FIELDS.name, group: 'basics' }, + email: { ...FIELDS.email, group: 'basics' }, + phone: FIELDS.phone, + owner_id: FIELDS.owner_id, + }, + }); + expect(within(detailsColumn(container)).getByText('Other')).toBeTruthy(); + + expect(footerOwner(container)).toBeNull(); + expect(ownerCount(container)).toBe(1); + }); +}); + +describe('the body does not draw owner_id: the meta line keeps the owner (objectstack#35941)', () => { + it('groups that leave owner_id out, and owner_id drawn nowhere else (hidden): the owner is on the meta line', () => { + const { container } = renderDefaultPage({ + name: OBJECT, + fieldGroups: [{ key: 'basics', label: 'Basics' }], + fields: { + name: { ...FIELDS.name, group: 'basics' }, + email: { ...FIELDS.email, group: 'basics' }, + phone: { ...FIELDS.phone, group: 'basics' }, + owner_id: { ...FIELDS.owner_id, hidden: true }, + }, + }); + expect(within(detailsColumn(container)).getByText('grace@example.com')).toBeTruthy(); + + expect(footerOwner(container)).not.toBeNull(); + expect(footerOwner(container)!.textContent).toContain(OWNER_NAME); + expect(ownerCount(container)).toBe(1); + }); + + it('a collapsed group holding owner_id: the owner is on the meta line until the group opens, then in the body', () => { + const { container } = renderDefaultPage({ + name: OBJECT, + fieldGroups: [ + { key: 'basics', label: 'Basics' }, + { key: 'ownership', label: 'Ownership', collapse: 'collapsed' }, + ], + fields: { + name: { ...FIELDS.name, group: 'basics' }, + email: { ...FIELDS.email, group: 'basics' }, + phone: { ...FIELDS.phone, group: 'basics' }, + owner_id: { ...FIELDS.owner_id, group: 'ownership' }, + }, + }); + // Collapsed, the group draws its heading and no rows. + expect(footerOwner(container)).not.toBeNull(); + expect(ownerCount(container)).toBe(1); + + fireEvent.click(within(detailsColumn(container)).getByRole('button', { name: /Ownership/ })); + expect(footerOwner(container)).toBeNull(); + expect(ownerCount(container)).toBe(1); + }); +}); diff --git a/ui/packages/plugin-detail/src/DetailSection.tsx b/ui/packages/plugin-detail/src/DetailSection.tsx index 2d01ab7b877..f0ebc46e265 100644 --- a/ui/packages/plugin-detail/src/DetailSection.tsx +++ b/ui/packages/plugin-detail/src/DetailSection.tsx @@ -61,6 +61,8 @@ import { InlineFieldInput } from './InlineFieldInput'; import { headerColorClass } from './headerColor'; import { DetailsColumnCapContext, framelessSectionColumns, useDefaultRecordPage } from './defaultRecordPage'; import { hasCellValue } from './emptiness'; +import { RecordPageProvenanceContext } from './recordPageProvenance'; +import { useReportBodyFields } from './recordBodyFields'; import { enrichDetailField, isComputedDetailField, @@ -140,6 +142,9 @@ export function framelessSpanClass(span: number | undefined, columns: 1 | 2 | 3) */ const ignoreReadOnlyChange = (): void => {}; +/** What a section reports while it draws no row of the page's record. */ +const NO_REPORTED_FIELDS: readonly string[] = []; + /** * Whether a key pressed on a copy-on-activate row is the ROW's own activation * (objectui#12569): Enter or Space, aimed at the row itself. @@ -482,6 +487,17 @@ export const DetailSection: React.FC = ({ undefined, objectSchema?.fields, ); + // objectstack#35941 — the page's meta line leaves the owner out when the + // body draws `owner_id`, so the body says which rows it draws: the rows of + // the grid below, none while its content is collapsed away (the faces + // below mount it only open: the frameless face and the card disclosure; + // the card that cannot collapse always draws it), and only for the page's + // own record. + const drawsPageRecord = React.useContext(RecordPageProvenanceContext); + const drawsContent = !isCollapsed || (!frameless && !section.collapsible); + useReportBodyFields( + drawsPageRecord && drawsContent ? layoutFields.map((field) => field.name) : NO_REPORTED_FIELDS, + ); // Never render more columns than there are visible fields — the object-wide // column count (objectui#2578) can exceed a section's visible count when // empty fields are hidden; a lone field shouldn't sit at 1/N width. diff --git a/ui/packages/plugin-detail/src/RecordMetaFooter.tsx b/ui/packages/plugin-detail/src/RecordMetaFooter.tsx index 812ef1407bb..196e44dde34 100644 --- a/ui/packages/plugin-detail/src/RecordMetaFooter.tsx +++ b/ui/packages/plugin-detail/src/RecordMetaFooter.tsx @@ -17,6 +17,7 @@ import { useDetailTranslation } from './useDetailTranslation'; import { hasCellValue } from './emptiness'; import { useDefaultRecordPage } from './defaultRecordPage'; import { deriveHighlightFields } from './synth/buildDefaultPageSchema'; +import { useBodyDrawnFieldNames } from './recordBodyFields'; /** * The record's reassignable owner column — the canonical injected @@ -246,6 +247,9 @@ export const RecordMetaFooter: React.FC = ({ // names the record's owner and its id (the v3 meta line: created · updated // · owner · id), at the foot of the details column. const v3MetaLine = useDefaultRecordPage(); + // The fields the page's body draws (objectstack#35941), read before the + // early return so hook order never varies; `null` outside the laid-out page. + const bodyFields = useBodyDrawnFieldNames(); if (!data) return null; const createdAt = toDate(data[AUDIT_FIELDS.createdAt]); @@ -263,14 +267,20 @@ export const RecordMetaFooter: React.FC = ({ const hasUpdated = !!(updatedAt || updatedBy) && !(updateIsSameAsCreate && (sameUser || !updatedBy)); - // The owner is named ONCE on the page (objectstack#28868): when the - // highlight strip the page draws carries the owner field, the strip names it - // and this line leaves it out. The host that draws the strip says which - // fields it drew; without that, the strip is the object's declared - // highlights, read by the one function every reader of the strip asks. + // The owner is named ONCE on the page (objectstack#28868): when the page + // already draws the owner field, this line leaves it out. Two places draw + // it. The highlight strip: the host that draws the strip says which fields + // it drew; without that, the strip is the object's declared highlights, + // read by the one function every reader of the strip asks. And the body + // (objectstack#35941): a details section of the page's record that draws + // the `owner_id` row, where the owner can also be changed, as the sections + // themselves report it. A row the reader cannot see (denied, hidden by a + // `visibleWhen`, in a collapsed section) is not reported, so the owner + // stays here. const stripFields = drawnHighlightFields ?? deriveHighlightFields(objectSchema, null); const stripNamesOwner = stripFields.includes(OWNER_FIELD); - const owner = v3MetaLine && !stripNamesOwner ? actorOrNone(data[OWNER_FIELD]) : undefined; + const bodyDrawsOwner = bodyFields?.has(OWNER_FIELD) === true; + const owner = v3MetaLine && !stripNamesOwner && !bodyDrawsOwner ? actorOrNone(data[OWNER_FIELD]) : undefined; const recordId = v3MetaLine && hasCellValue(data.id) ? String(data.id) : undefined; if (!hasCreated && !hasUpdated && !owner && !recordId) return null; diff --git a/ui/packages/plugin-detail/src/RecordPageColumns.tsx b/ui/packages/plugin-detail/src/RecordPageColumns.tsx index f9b2d226ff0..8b8e1b009b3 100644 --- a/ui/packages/plugin-detail/src/RecordPageColumns.tsx +++ b/ui/packages/plugin-detail/src/RecordPageColumns.tsx @@ -28,6 +28,7 @@ import { useRecordAttachmentCount, } from './RecordSummaryRail'; import { RecordTimelineCountContext } from './recordTimelineStream'; +import { createRecordBodyFields, RecordBodyFieldsContext } from './recordBodyFields'; import { RecordTimelineCountProbe } from './renderers/record-activity'; import { editRelatedArrangement, @@ -359,6 +360,10 @@ export const RecordPageColumns: React.FC = ({ const { t } = useDetailTranslation(); const ctx = useRecordContext(); const bodyTableIds = React.useMemo(() => new Set(relatedListIdsIn(columns.details)), [columns.details]); + // objectstack#35941 — the details sections report the rows they draw, and + // the meta line closing the details column reads them: the owner is left + // off that line when a section already draws `owner_id`. + const [bodyFields] = React.useState(createRecordBodyFields); const hasTimeline = columns.timeline.length > 0; const wide = tier === 'wide'; const besideDetails = tier !== 'stack'; @@ -607,6 +612,7 @@ export const RecordPageColumns: React.FC = ({ const template = sideBySide ? (wide ? GRID_TEMPLATE.wide : GRID_TEMPLATE.twoColumn) : GRID_TEMPLATE.oneColumn; return ( + @@ -652,5 +658,6 @@ export const RecordPageColumns: React.FC = ({ + ); }; diff --git a/ui/packages/plugin-detail/src/recordBodyFields.ts b/ui/packages/plugin-detail/src/recordBodyFields.ts new file mode 100644 index 00000000000..d43869520ac --- /dev/null +++ b/ui/packages/plugin-detail/src/recordBodyFields.ts @@ -0,0 +1,114 @@ +/** + * ObjectUI + * Copyright (c) 2024-present ObjectStack Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +import * as React from 'react'; + +/** + * The fields the record page's BODY draws, as the body draws them + * (objectstack#35941). + * + * The page's meta line names the record's owner. When a details section on + * the page already draws `owner_id`, the owner shows there, as a field the + * reader can change, so the meta line leaves it out and the owner appears + * once. Which fields the body draws is not something a page host can read + * off the page tree: a field lands in a declared group, in the derived + * "other" bucket or in the auto-split sections, and the body then drops + * what the reader may not read, what a `visibleWhen` hides, a group whose + * own `visibleWhen` is false, and the rows of a collapsed section. So the + * answer comes from the body itself: every `DetailSection` that draws the + * page's record reports the field rows it draws, and the meta line reads + * the union. A row the reader cannot see is not reported, so the owner never + * goes missing from both places. + * + * "The page's record" is the record `record:details` reads when it carries + * no data binding (`RecordPageProvenanceContext`). A section drawn for any + * other record, such as a bound `record:details`, or a drawer opened from a + * related list (a React portal keeps the page's context), reports nothing. + * + * Module-internal on purpose, the way `RecordPageProvenanceContext` is: not + * in the package barrel, and neither a prop nor a schema key. The laid-out + * record page (`RecordPageColumns`) mounts the registry around the details + * column and the meta line it closes with. Outside a registry the meta line + * reads `null` and keeps its strip-only rule. + */ +export interface RecordBodyFields { + /** The union of the reported field names; a new set whenever it changes. */ + getNames: () => ReadonlySet; + subscribe: (listener: () => void) => () => void; + /** Report the rows one section draws; an empty list withdraws them. */ + report: (sectionId: string, names: readonly string[]) => void; + withdraw: (sectionId: string) => void; +} + +const EMPTY_NAMES: ReadonlySet = new Set(); + +export function createRecordBodyFields(): RecordBodyFields { + const bySection = new Map(); + const listeners = new Set<() => void>(); + let names: ReadonlySet = EMPTY_NAMES; + const recompute = () => { + const next = new Set(); + for (const list of bySection.values()) for (const name of list) next.add(name); + if (next.size === names.size && Array.from(next).every((name) => names.has(name))) return; + names = next; + for (const listener of Array.from(listeners)) listener(); + }; + return { + getNames: () => names, + subscribe(listener) { + listeners.add(listener); + return () => { + listeners.delete(listener); + }; + }, + report(sectionId, list) { + if (list.length === 0) { + if (bySection.delete(sectionId)) recompute(); + return; + } + bySection.set(sectionId, [...list]); + recompute(); + }, + withdraw(sectionId) { + if (bySection.delete(sectionId)) recompute(); + }, + }; +} + +export const RecordBodyFieldsContext = React.createContext(null); + +const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect; + +/** + * Report the field rows a section draws, for as long as it draws them. A + * layout effect, so the meta line has its answer before the page paints. + * Nothing is reported outside a registry. + */ +export function useReportBodyFields(names: readonly string[]): void { + const registry = React.useContext(RecordBodyFieldsContext); + const sectionId = React.useId(); + const key = names.join('|'); + useIsomorphicLayoutEffect(() => { + if (!registry) return undefined; + registry.report(sectionId, key.length === 0 ? [] : key.split('|')); + return () => registry.withdraw(sectionId); + }, [registry, sectionId, key]); +} + +const NO_SUBSCRIPTION = () => () => {}; +const NO_NAMES = (): ReadonlySet | null => null; + +/** The fields the page's body draws, or `null` when no registry is mounted. */ +export function useBodyDrawnFieldNames(): ReadonlySet | null { + const registry = React.useContext(RecordBodyFieldsContext); + return React.useSyncExternalStore | null>( + registry ? registry.subscribe : NO_SUBSCRIPTION, + registry ? registry.getNames : NO_NAMES, + registry ? registry.getNames : NO_NAMES, + ); +}