Repository navigation
Commit 08bf7d2
fix(components): action:button renders no text for a non-string label instead of crashing the page (#37262)
Fixes #36717
Clause-②: no
Metadata-protocol: none
## 维护者速读
-
页面上的操作按钮,文字若不是字符串(例如代码注册、没过校验的页面里写成多语言对象),以前整页白屏;现在按钮照常显示并可点击,只是不显示文字,开发环境会提示一次。字符串文字的显示与翻译和以前完全一样。
- 执行维护者裁决「保持走翻译包」(选项
A):按钮文字仍只接受字符串,靠翻译包里该组件的条目翻译;本次只加渲染防护,不翻译多语言对象,也不改协议。
-
出错的后果:最坏是那个按钮没有文字,页面其余部分不受影响;改动可直接撤回。另有一处行为变化:以前写成数字的按钮文字会照样显示,现在同样不显示并提示一次(协议本来就只接受字符串)。
- 要你做的:无。
## What changes
`ui/packages/components/src/renderers/action/action-button.tsx`: every
read of `schema.label` goes through one guard, `renderableLabel`. A
string label is returned unchanged. Any other value (an inline locale
map from metadata that skipped `validateComponentProps`) becomes no
label: the button renders with no text and still runs its action,
nothing prints `[object Object]`, and a development build logs one
`console.warn` per component, keyed on the component id, naming the
bundle key `pages.PAGE.components.COMPONENT_ID.label`. The dev warning
follows the existing `process.env.NODE_ENV !== 'production'` pattern in
`auto-trigger.ts`. The value is never translated, so a value the
contract refuses gets no meaning.
The guard covers all five label reads in the file: the `visible`
diagnostic label, the `label` forwarded to the runner (the param
dialog's title), the icon spacing class, the rendered text, and the
subject handed to `useAutoTriggerOnce`. That hook builds its user-facing
refusal toast and toast id from the label, so it now gets the guarded
label (`{ ...schema, label }` when they differ).
Ruling: option A (7118756694), the maintainer's 「保持走翻译包」. `label` stays
`z.string()` and `packages/spec` is untouched.
Responsibility:
- whose code: the platform's own `@object-ui/components` `action:button`
renderer;
- existing platform path: the translation bundle key for the component
id, which is the contract and already translates a string label;
- who reaches it: pages whose metadata skipped `validateComponentProps`
(for example code-registered pages) and carry a non-string label.
## Tests
A new top-level `describe` for #36717 in the existing action-button
harness `action-button-icon-inputs-11168.test.tsx`, which mounts the
node through the real `SchemaRenderer` and `ActionProvider`:
- an object label renders the button with empty text, shows no `[object
Object]` and neither locale string, and a second mount of the same
component does not warn again (exactly one warning, which names the
component id);
- an object label still runs the action, and the runner gets no label;
- an object label on a hidden `autoTrigger` button gives a refusal toast
whose message and id carry no `[object Object]` (it names the action by
`name`), and no console warning carries it either;
- CONTROL: a string label renders and is forwarded to the runner;
- CONTROL: a string label translated by `translatePage` through
`pages.billing.components.buy_credits.label` renders `购买额度`.
## Acceptance notes
- Behaviour change: a numeric label (for example `5`) rendered as text
before this PR. It is now dropped like any other non-string label, with
the same dev warning. The contract (`z.string()`) already refuses it, so
this follows ruling A.
- Same defect family, out of this card's reach: `action:menu`,
`action:group` and `action:icon` also render a non-string label raw, and
`action:menu` throws on a locale map. The follow-up is #37266.
- The dev warning is keyed on the component id, then `name`. A button
with neither shares the fallback key `action:button`, so only the first
such button warns.
- A button with a non-string label and no icon has no accessible name.
That follows from the ruling's "render no text", and the dev warning
names the fix.
## Verification
Two-minute check: `pnpm --dir ui exec vitest run
packages/components/src/renderers/action/__tests__/action-button-icon-inputs-11168.test.tsx
-t "non-string label"`. Expected: 5 passed.
<details><summary>Ablation of the auto-trigger hand-off (head
fce37f7)</summary>
`node scripts/ablation-replace.mjs` put back `useAutoTriggerOnce(schema,
isVisible, handleClick)` (anchor 1 to 0, blob 60bb1f1 to
426c38142ef3). Result: 1 failed, 4 passed. The failure: `expected
'"[object Object]" is not available on…' not to contain '[object
Object]'`. After the restore, the blob equals HEAD (60bb1f1) and
`git diff HEAD` is empty.
The first version of this pin (da40a35) mounted the node through
`SchemaRenderer`. Its node gate hides a `visible: false` node before the
renderer mounts, so the hook never ran and the toast was never called;
that failed the same way locally and in CI. It was a mounting error, not
timing. The pin now mounts the registered renderer directly, which is
the path `action:bar` takes.
</details>
<details><summary>Ablation (guard reverted, head e8894fd)</summary>
`node scripts/ablation-replace.mjs` replaced the guard's string check
with `return label as string | undefined;`. The anchor went from 1 to 0
hits and the blob from 212e689 to 4aa3e1708bd4. Result: 2 failed, 2
passed. Both object-label tests threw "Objects are not valid as a React
child (found: object with keys {en, zh-CN})", which is the defect as it
is on main. Both controls stayed green. After the restore, the blob
equals HEAD (212e689) and `git diff HEAD` is empty.
</details>
<details><summary>Suites and gates (round 1 head e13c940; round 2 head
fce37f7 below)</summary>
- Round 2 at fce37f7: `pnpm --filter @object-ui/components type-check &&
vitest run packages/components/src/renderers/action/` gave 37 files and
619 tests passed (VERDICT command-exit 0). The harness file gave 60/60.
- `pnpm --filter @object-ui/components type-check` passed, chained with
`&&` before `vitest run packages/components/src/renderers/action/` (38
files, 626 tests passed). VERDICT command-exit 0.
- Full `packages/components/` suite on e8894fd: 510 files passed, 1
skipped; 4970 tests passed. The only later code change is the warning
key (`dataObjId`), and the action-renderer directory was re-run on the
final head.
- `dispatch-gates --commands`: 38 families derived and run; `--ran`
accounted for all 38. 37 exited 0 on e13c940. `vitest run scripts/` had
one 15 s timeout under box contention
(`js-comment-mask-returns-interpolation-9424`). That file passed on
re-run under the lock on the final head.
- NOT MEASURED locally: the CI type-check lanes the derivation lists as
CI-only, the CI-measured-only families, and Test UI shards beyond
`packages/components`.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01QSeKYmRepQK9DkZeU7F53D)_
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01QSeKYmRepQK9DkZeU7F53D
<!-- signed: repo:objectstack#4 · os-justin ·
session_01QSeKYmRepQK9DkZeU7F53D -->
---------
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>1 parent 4fb03eb commit 08bf7d2
3 files changed
Lines changed: 155 additions & 6 deletions
File tree
- .changeset
- ui/packages/components/src/renderers/action
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| 70 | + | |
70 | 71 | | |
71 | 72 | | |
72 | 73 | | |
| 74 | + | |
73 | 75 | | |
74 | 76 | | |
75 | 77 | | |
| |||
606 | 608 | | |
607 | 609 | | |
608 | 610 | | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
45 | 71 | | |
46 | 72 | | |
47 | 73 | | |
| |||
156 | 182 | | |
157 | 183 | | |
158 | 184 | | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
159 | 195 | | |
160 | 196 | | |
161 | 197 | | |
| |||
179 | 215 | | |
180 | 216 | | |
181 | 217 | | |
182 | | - | |
| 218 | + | |
183 | 219 | | |
184 | 220 | | |
185 | 221 | | |
| |||
292 | 328 | | |
293 | 329 | | |
294 | 330 | | |
295 | | - | |
| 331 | + | |
296 | 332 | | |
297 | 333 | | |
298 | 334 | | |
| |||
411 | 447 | | |
412 | 448 | | |
413 | 449 | | |
414 | | - | |
| 450 | + | |
415 | 451 | | |
416 | 452 | | |
417 | 453 | | |
| |||
425 | 461 | | |
426 | 462 | | |
427 | 463 | | |
428 | | - | |
| 464 | + | |
429 | 465 | | |
430 | 466 | | |
431 | 467 | | |
| |||
485 | 521 | | |
486 | 522 | | |
487 | 523 | | |
488 | | - | |
489 | | - | |
| 524 | + | |
| 525 | + | |
490 | 526 | | |
491 | 527 | | |
492 | 528 | | |
| |||
0 commit comments