Repository navigation
Commit 39fa82b
fix(components): header-action predicates wait for the record instead of reporting "No such key" (#34035)
<!-- claude-projects-attribution: {"github_login":"os-steve"} -->
_Requested by **Steve** · [project
thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9E8CzBpSUdLhr9L1Yhzma3U)_
Fixes #33987
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 改了什么:记录页头部按钮的 `visible` / `hidden` / `disabled` / `pressed`
条件,在记录还没加载完时不再求值,也不再往控制台报错;记录到了再正常求值。
- 为什么改:页面一打开就拿一条空记录去算条件,每个 `record.status` 这类条件都报 “No such key… check
the field names and CEL”,让作者去改其实没错的元数据。
- 风险与回滚:只动 `page:header` 一个组件;加载中各条件取各自的安全默认值(隐藏 / 不隐藏 / 禁用 /
未按下),与之前出错时的取值一致,记录到了以后行为不变。回滚即还原这一个提交。
- 先看:`ui/packages/components/src/renderers/layout/containers.tsx` 的
`headerRecordPending` 与 `evalHeaderPredicate`;再看
`page-header-predicate-dialect.test.tsx` 末尾新增的一组测试。
- 两分钟验证:`cd ui && pnpm exec vitest run
packages/components/src/__tests__/page-header-predicate-dialect.test.tsx`,预期
33 条全绿。
- 需要你做的:无,席位落地。
## What changes
A record page binds its record id at once and its row only when the read
answers (`RecordDetailView` hands `data: null` until then;
`RecordContextValue.data` is documented as "undefined while loading").
`page:header` evaluated its action predicates against `ctx?.data ?? {}`,
so during that window every `record.FIELD` predicate faulted with "No
such key", and the warn-once fault report (keyed by label and predicate)
told the author to check the field names of a field the object has, on
every page load.
- `headerRecordPending` names the state: a record context is present, it
carries a record id, and its row is `null`/`undefined`.
- `evalHeaderPredicate` answers each key's own fallback while pending
and evaluates nothing, so nothing is reported. All four call sites
(`visible`, `hidden`, `disabled`, `pressed`) go through it.
- `disabledReasonFor` gives no "Not available for this record" reason
while pending: the closed `disabled` fallback is not a fact about a
record that has not arrived. Same defect class (a pending record
reported as a fact about the record), same file, same gate families.
- Unchanged: a header with no record bound (no context, or no id) still
evaluates, so a `record.*` predicate there still faults and says so; a
loaded record that really lacks the key still warns once.
No change in `ui/packages/core/src/evaluator/**`: the evaluator is right
to fault on an empty record; the root cause is the caller spelling an
absent record as an empty one.
## Tests
One new top-level `describe` in the existing shared harness
`page-header-predicate-dialect.test.tsx` (no new file):
- pending → no fault report, `visible` answers hidden; record arrives →
predicate honoured (shown), still no report;
- loaded negative direction → hidden, no report;
- pending `hidden` / `disabled` / `pressed` → rendered, disabled,
`aria-pressed="false"`, no `aria-describedby` reason, no report; after
load → enabled, pressed, no report;
- CONTROL: a loaded record missing `f_status` → hidden and exactly one
fault naming `f_status`;
- CONTROL: no record id bound → still faults once.
No existing test was edited.
## Acceptance notes
- Triage asked whether the rendered buttons are wrong after the record
loads. Measured on the shipped code (fix ablated, same harness): pending
`[false,false]` with 2 fault reports; after load `[true,false]`, which
is the predicates' own verdict. So only the pre-load pass was wrong; the
authored rule was already honoured once the record arrived. With the
fix: pending `[false,false]`, 0 reports; loaded `[true,false]`, 0
reports.
- While pending, a predicate that reads only the host scope (for example
`ctx.user.isPlatformAdmin == true`) also waits for the record, where it
used to evaluate at once. The header shows its record-gated and
user-gated actions together, once the row arrives.
## Verification
<details><summary>Ablations (fix committed first; restored blob == HEAD
each time)</summary>
- `headerRecordPending` forced to `false`: 3 of the 5 new tests red
(`expected [ Array(1) ] to have a length of +0 but got 1` on both
pending fault-count pins; the legs test red on `aria-describedby`); both
CONTROL tests stay green.
- only the `disabledReasonFor` pending line deleted: 1 red (the legs
test, `aria-describedby`).
</details>
<details><summary>Local runs at a1d4af3</summary>
- `cd ui && pnpm exec vitest run
packages/components/src/__tests__/page-header-predicate-dialect.test.tsx`:
33/33 passed.
- `pnpm --filter @object-ui/components test --maxWorkers=2` (under the
verify lock): Test Files 479 passed, 1 skipped (480); Tests 4595 passed,
24 skipped.
- `pnpm --filter @object-ui/components type-check` (after building the
dependency closure): exit 0.
- `node scripts/pm/dispatch-gates.mjs --commands`: 37 derived families,
each run, all exit 0; `--ran` reconciliation: 37 run, 0 NOT-MEASURED, 0
UNRUN. `pnpm --dir ui exec vitest run scripts/` first exited 1 only
because `@objectstack/client` had no build in this container
(unresolved-entry list); after the build it passed 171 files / 5065
tests.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01ADHkmQj66qNAyERYxzoNgw)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 63db724 commit 39fa82b
3 files changed
Lines changed: 143 additions & 8 deletions
File tree
- .changeset
- ui/packages/components/src
- __tests__
- renderers/layout
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
361 | 361 | | |
362 | 362 | | |
363 | 363 | | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2053 | 2053 | | |
2054 | 2054 | | |
2055 | 2055 | | |
| 2056 | + | |
| 2057 | + | |
| 2058 | + | |
| 2059 | + | |
| 2060 | + | |
| 2061 | + | |
| 2062 | + | |
| 2063 | + | |
| 2064 | + | |
2056 | 2065 | | |
2057 | 2066 | | |
2058 | 2067 | | |
| |||
2104 | 2113 | | |
2105 | 2114 | | |
2106 | 2115 | | |
| 2116 | + | |
| 2117 | + | |
| 2118 | + | |
| 2119 | + | |
| 2120 | + | |
| 2121 | + | |
| 2122 | + | |
| 2123 | + | |
2107 | 2124 | | |
2108 | 2125 | | |
2109 | 2126 | | |
2110 | | - | |
2111 | | - | |
2112 | | - | |
2113 | | - | |
2114 | | - | |
2115 | | - | |
2116 | | - | |
2117 | | - | |
| 2127 | + | |
| 2128 | + | |
| 2129 | + | |
| 2130 | + | |
| 2131 | + | |
| 2132 | + | |
| 2133 | + | |
| 2134 | + | |
| 2135 | + | |
| 2136 | + | |
2118 | 2137 | | |
2119 | 2138 | | |
2120 | 2139 | | |
| |||
2557 | 2576 | | |
2558 | 2577 | | |
2559 | 2578 | | |
| 2579 | + | |
| 2580 | + | |
| 2581 | + | |
2560 | 2582 | | |
2561 | 2583 | | |
2562 | 2584 | | |
| |||
0 commit comments