fix(app-shell): page block inspector authors visibleWhen, not hidden (#3229) - #3286
Merged
Merged
Conversation
…en` (#3229) The conditional-visibility `ConditionBuilder` on the selected page block read and wrote `block.hidden`. `PageComponentSchema` (`ui/page.zod.ts`) is `.strict()` and has no `hidden` key, so the designer — a PRODUCER — was emitting drafts guaranteed to fail parse on save, naming a key the author never typed. The canonical key is `visibleWhen` (ADR-0089). The control now reads/writes `visibleWhen` through the shared expression envelope pair (#3218), since `visibleWhen` is `ExpressionInputSchema` and a persisted block carries `{ dialect, source }` rather than the authored string. The semantic flip lands in the UI copy too — `hidden` and `visibleWhen` are inverses, so the label and the i18n key move with it (`engine.inspector.pageBlock.hidden` → `.visibleWhen`, both language packs: "Hidden (CEL)" → "Visible when (CEL)", 隐藏条件 → 显示条件). Renaming the key under hide-flavoured copy would make authors write predicates backwards — metadata that parses and means the opposite (the #3276 class, which #3257's parse guard is structurally blind to). No value is migrated: negating an arbitrary CEL predicate textually is unsound, and since ADR-0089 D3a no valid stored draft can carry `hidden` anyway. Tests pin DIRECTION, not just the key name: the block the inspector actually commits is rendered through SchemaRenderer and must appear when its predicate is true and be absent when false. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NVPjPzmmAJ2Ngtvgg5MSRa
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Contributor
✅ Console Performance Budget
📦 Bundle Size Report
Size Limits
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3229
按 PM 裁定的方案 A 实现(A/B 已与维护者敲定,本 PR 不再重开该讨论)。
缺陷
PageBlockInspector.tsx给选中 page 块渲染的条件构建器读写的是block.hidden。而@objectstack/spec的PageComponentSchema(ui/page.zod.ts)是.strict()的,键集合里根本没有hidden。关键点是方向:这不是「消费端太宽容」,而是生产者在批量产出契约必然拒收的元数据。作者在这个框里填任何东西,保存时都会拿到一个指名了自己从没输入过的键的解析错误 —— 那个键是检查器替他填的。spec 的报错自己就写明了修法(
the canonical key is visibleWhen)。改动
ConditionBuilder改为读写visibleWhen(ADR-0089 canonical)。因为visibleWhen是ExpressionInputSchema,已持久化的块携带的是{ dialect, source }信封而非作者输入的字符串,所以走 Hook 检查器把{ dialect, source }信封形式的condition读成空字符串,提交时会清掉它 #3218 落地的共享读写对expressionSource/writeExpressionSource—— 一次编辑会保留dialect与meta、丢弃已陈旧的ast,而不是把信封拍平成裸字符串、悄悄换掉求值引擎。hidden与visibleWhen互为反义,所以标签、i18n key、双语文案一起走 ——engine.inspector.pageBlock.hidden→.visibleWhen,Hidden (CEL)→Visible when (CEL),「隐藏条件(CEL)」→「显示条件(CEL)」。hidden?: string→visibleWhen?: ExpressionInput。同时补上了原单指出的第三个缺口:一个合法的块(带
visibleWhen)此前在检查器里没有任何控件能编辑它的可见性 —— 屏幕上唯一的可见性控件写的是错键。两件明确没做的事
没有把旧
hidden表达式取反塞进visibleWhen。 对任意 CEL 表达式做文本取反不成立(!(a && b)不是!a && !b);而且根本不存在需要迁移的存量 —— ADR-0089 D3a 之后hidden在保存时就是响亮解析失败,D3a 之前该键在 parse 时被静默剥掉,同样进不了已发布的元数据。让稀有的陈旧草稿走响亮报错(报错本身就是迁移指引),比静默改写作者的谓词安全。没有只换键名而留下 hidden 语义的文案。 那会让作者把条件写反,产出「能 parse 但语义相反」的元数据 —— 正是 objectui#3276 那一类,而 #3257 的守卫结构上抓不到它(它只问能不能 parse)。
测试:钉住方向,不只是键名
新增
PageBlockInspector.visibleWhen.test.tsx(11 例)。沿用 #3216 的 fixture 纪律:不手写信封,所有 fixture 都是作者输入喂给PageSchema.parse的结果。SchemaRenderer(即PageBlockCanvas使用的渲染器)—— 谓词为真时块渲染,为假时不渲染。两个方向互为佐证:谓词若失效会 fail-soft 成可见,那样「为假」这条就会红。visibleWhen,不是hidden;提交后的草稿能PageSchema.parse通过(并反向钉住旧hidden形状确实会抛错)。dialect/meta)、清空回落undefined、从零新建时提交裸字符串简写。Visible when且不出现Hidden;中文断言出现「显示条件」且不出现「隐藏条件」。验证结果
type-check在全新 worktree 里因为兄弟包未构建会有 866 条Cannot find module '@object-ui/*'级联报错 —— 我用 stash 把改动摘掉跑了同一条命令做基线对比:基线 866 / 本分支 866,逐条 diff 只有行号位移(我加了 import 与注释),本改动零新增类型错误。范围
严格限定在
views/metadata-admin/inspectors/+ 共享 i18n 语言包。语言包只改了自己的 2 行(每个语种 1 行),没有重排或重新格式化任何既有条目,避免与并行 agent 冲突。未触碰previews/(#3275)与RecordDetailView.tsx(#3268)。已附 changeset(
patch,未声明major,已过check-changeset-no-major.mjs)。🤖 Generated with Claude Code
https://claude.ai/code/session_01NVPjPzmmAJ2Ngtvgg5MSRa
Generated by Claude Code