From 809c57a004938d3f20ec49cb73c97347216e75c2 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 16:17:08 +0000 Subject: [PATCH 1/2] fix(components): evaluate page:header action predicates once the record arrives While the record page's read is in flight the header bound an empty record, so every record. predicate faulted with "No such key" and the warn-once report told the author to check field names the object has. A bound record id with no row is now its own pending state: each predicate answers its key's fallback and reports nothing until the row arrives. Claude-Session: https://claude.ai/code/session_01ADHkmQj66qNAyERYxzoNgw Co-authored-by: Claude --- .../page-header-predicate-dialect.test.tsx | 100 ++++++++++++++++++ .../src/renderers/layout/containers.tsx | 38 +++++-- 2 files changed, 130 insertions(+), 8 deletions(-) diff --git a/ui/packages/components/src/__tests__/page-header-predicate-dialect.test.tsx b/ui/packages/components/src/__tests__/page-header-predicate-dialect.test.tsx index bf0b4d145e9..eec57dc877c 100644 --- a/ui/packages/components/src/__tests__/page-header-predicate-dialect.test.tsx +++ b/ui/packages/components/src/__tests__/page-header-predicate-dialect.test.tsx @@ -361,3 +361,103 @@ describe('page:header — fail-closed stays fail-closed, and says so once (#3521 } }); }); + +describe('page:header — a record still loading is its own state, not an empty record (objectstack#33987)', () => { + // The record page binds its record id at once and hands `data: null` until + // the read answers. Evaluating then meant evaluating against an empty + // record: every `record.` predicate faulted with "No such key", and + // the warn-once report told the author to check the field names of a field + // the object HAS — on every load, before the record arrived. + const faultsFor = (warn: ReturnType, name: string) => + warn.mock.calls.filter( + (c: unknown[]) => String(c[0]).includes('failed to evaluate') && String(c[0]).includes(`"${name}"`), + ); + + function headerTree(action: Record, recordId: string | null, data: any) { + return ( + + + + + + + + ); + } + + let warn: ReturnType; + beforeEach(() => { + warn = vi.spyOn(console, 'warn').mockImplementation(() => {}); + return () => warn.mockRestore(); + }); + + it('pending: no fault report; once the record arrives the predicate is honoured, still with no report', () => { + const action = { name: 'zoo_pending_visible_33987', visible: 'record.f_status == "open"' }; + const { rerender } = render(headerTree(action, 'r1', null)); + // Pending answers the key's own fallback (hidden), and says nothing. + expect(shown()).toBe(false); + expect(faultsFor(warn, 'zoo_pending_visible_33987')).toHaveLength(0); + + rerender(headerTree(action, 'r1', RECORD)); + expect(shown()).toBe(true); + expect(faultsFor(warn, 'zoo_pending_visible_33987')).toHaveLength(0); + }); + + it('the loaded verdict is the predicate’s own in the negative direction too', () => { + const action = { name: 'zoo_pending_negative_33987', visible: 'record.f_status == "open"' }; + const { rerender } = render(headerTree(action, 'r1', undefined)); + rerender(headerTree(action, 'r1', { ...RECORD, f_status: 'closed' })); + expect(shown()).toBe(false); + expect(faultsFor(warn, 'zoo_pending_negative_33987')).toHaveLength(0); + }); + + it('pending: `hidden`, `disabled` and `pressed` report nothing either, and `disabled` claims no reason about the record', () => { + const action = { + name: 'zoo_pending_legs_33987', + hidden: 'record.f_status == "closed"', + disabled: 'record.f_status == "closed"', + pressed: 'record.f_status == "open"', + }; + const { rerender } = render(headerTree(action, 'r1', null)); + // Each leg answers its own fallback: rendered, disabled, not pressed. + expect(shown()).toBe(true); + expect(button()).toBeDisabled(); + expect(button()).toHaveAttribute('aria-pressed', 'false'); + expect(button()).not.toHaveAttribute('aria-describedby'); + expect(faultsFor(warn, 'zoo_pending_legs_33987')).toHaveLength(0); + + rerender(headerTree(action, 'r1', RECORD)); + expect(shown()).toBe(true); + expect(button()).not.toBeDisabled(); + expect(button()).toHaveAttribute('aria-pressed', 'true'); + expect(faultsFor(warn, 'zoo_pending_legs_33987')).toHaveLength(0); + }); + + it('CONTROL: a LOADED record really missing the key still faults, fails closed and says so once', () => { + const { f_status: _omitted, ...withoutStatus } = RECORD; + const action = { name: 'zoo_loaded_missing_33987', visible: 'record.f_status == "open"' }; + render(headerTree(action, 'r1', withoutStatus)); + expect(shown()).toBe(false); + const faults = faultsFor(warn, 'zoo_loaded_missing_33987'); + expect(faults).toHaveLength(1); + expect(String(faults[0][0])).toContain('f_status'); + }); + + it('CONTROL: a header with no record bound (no id) still evaluates, so a `record.*` predicate there faults and says so', () => { + const action = { name: 'zoo_unbound_33987', visible: 'record.f_status == "open"' }; + render(headerTree(action, null, undefined)); + expect(shown()).toBe(false); + expect(faultsFor(warn, 'zoo_unbound_33987')).toHaveLength(1); + }); +}); diff --git a/ui/packages/components/src/renderers/layout/containers.tsx b/ui/packages/components/src/renderers/layout/containers.tsx index 5234141821b..dbb8ad7e6d9 100644 --- a/ui/packages/components/src/renderers/layout/containers.tsx +++ b/ui/packages/components/src/renderers/layout/containers.tsx @@ -2053,6 +2053,15 @@ export const PageHeaderActions: React.FC = ({ // `warnOnError: true`), so a broken predicate hides its button here exactly // as it does on the other surfaces, and says so once. const headerPredicateFields = headerObjectSchema?.fields; + // The record this header is ABOUT has not arrived yet: a record is bound (the + // host named its id) and its row is still absent — `RecordContextValue.data` + // is "undefined while loading", and the record page hands `null` until its + // read answers. That is its own state, not an empty record: an empty record + // makes every `record.` predicate fault, which is an authoring error + // only when the key is missing from a record that DID load. A header with no + // record bound at all (no context, or no id) keeps evaluating as before, so a + // `record.*` predicate there still faults and says so. + const headerRecordPending = ctx != null && ctx.recordId != null && ctx.data == null; const headerPredicateScope = React.useMemo(() => { const scopeUser = (predicateScope as any)?.user; // Relation fields bind as the FOREIGN KEY the server stores, not as the @@ -2104,17 +2113,27 @@ export const PageHeaderActions: React.FC = ({ * share `visible`'s `false`, which on this key means ENABLED — so * `disabled: !current_user.can(…)` left the action pressable until the * payload arrived, the one leg of this surface that failed open. + * + * While the record is PENDING (see `headerRecordPending`) nothing is + * evaluated: every predicate answers its `fallback` and reports nothing. + * Evaluating then meant evaluating against an empty record, where every + * `record.` faults with "No such key" — and the fault report, which + * is warn-once per (label, predicate), told the author to "check the field + * names" of a field the object has, on every load, before the record it + * names had arrived. The predicate runs, and reports, once the record does. */ const evalHeaderPredicate = React.useCallback( (pred: unknown, label: string, fallback: boolean): boolean => - evalRowPredicate(pred as never, ctx?.data ?? {}, { - fallback, - scope: headerPredicateScope, - fields: headerPredicateFields, - warnOnError: true, - label, - }), - [ctx?.data, headerPredicateScope, headerPredicateFields], + headerRecordPending + ? fallback + : evalRowPredicate(pred as never, ctx?.data ?? {}, { + fallback, + scope: headerPredicateScope, + fields: headerPredicateFields, + warnOnError: true, + label, + }), + [ctx?.data, headerRecordPending, headerPredicateScope, headerPredicateFields], ); const headerActionPlan = React.useMemo<{ actions: any[]; authoredKeys: ReadonlySet }>(() => { @@ -2557,6 +2576,9 @@ export const PageHeaderActions: React.FC = ({ const disabledReasonFor = (action: any): string | undefined => { const key = (action?.name || action?.id || '') as string; if (key === '' || !authoredHeaderActionKeys.has(key)) return undefined; + // A pending record answers `disabled`'s fallback (closed), which is not + // a fact about the record — so it is not explained as one. + if (headerRecordPending) return undefined; if (!resolveDisabled(action?.disabled, action?.name ?? action?.id)) return undefined; const declared = typeof action?.disabledReason === 'string' ? action.disabledReason : ''; return declared.trim() !== '' From a1d4af391e317a27b49cac978dae74053d475b9d Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 16:20:01 +0000 Subject: [PATCH 2/2] chore(changeset): header-action predicates wait for the record Claude-Session: https://claude.ai/code/session_01ADHkmQj66qNAyERYxzoNgw Co-authored-by: Claude --- .../33987-header-predicates-pending-record.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .changeset/33987-header-predicates-pending-record.md diff --git a/.changeset/33987-header-predicates-pending-record.md b/.changeset/33987-header-predicates-pending-record.md new file mode 100644 index 00000000000..d981e65ed1a --- /dev/null +++ b/.changeset/33987-header-predicates-pending-record.md @@ -0,0 +1,13 @@ +--- +'@object-ui/components': patch +'@object-ui/console': patch +--- + +fix(components): record page header-action predicates wait for the record instead of reporting "No such key" for fields the object has + +Clause-②: no +Metadata-protocol: none + +A record page binds its record id at once and its row only when the read answers. Until then the `page:header` actions evaluated their `visible`, `hidden`, `disabled` and `pressed` predicates against an empty record, so every `record.` predicate faulted, and the console said "A conditional predicate failed to evaluate … No such key: status … Check the field names and CEL" once per action on every page load, for a field the object has. Nothing was wrong with the metadata. + +A record that is bound but not loaded is now its own state. Each predicate answers its key's safe default (hidden, not hidden, disabled, not pressed) and reports nothing; a `disabled` action does not claim it is "not available for this record" while there is no record yet. Once the record arrives the predicates run as before, and the warning still fires when a key is really missing from the loaded record. A header with no record bound at all evaluates as before.