fix(types,layout): 导航元数据不再丢掉渲染器本就在用的 spec 字段 (#4115) - #3088
Merged
Conversation
…he renderer already honours (objectstack#4115)
`objectui validate` — a published CLI command — is the ONLY runtime consumer
of objectui's zod schemas; renderers read plain objects and never parse. So
every gap below was a CLI defect, and because the schema strips unknown keys
instead of erroring, all of them failed silently.
Measured against spec 17.0.0-rc.0, `NavigationItemSchema` was:
- dropping `requiresObject` / `requiresService`. These are capability gates
that `NavigationItem` has always declared and `NavigationRenderer` has
always enforced — only the schema lagged, so validating an app stripped
the gates from its own nav metadata.
- dropping `actionDef`, i.e. an action item's entire payload. An item that
could never invoke anything validated clean.
- dropping `expanded`, the spec's spelling of group expansion. The renderer
already read it — behind `(item as any).expanded`, because the TS type did
not declare it. That cast is now gone.
- rejecting `badgeVariant: 'secondary'`, which the spec accepts. The union is
now derived from the spec's own `ObjectNavItem` instead of restated.
- rejecting `{ type: 'separator' }`, which the spec accepts and which carries
no identity or text by definition.
`NavigationArea` lost `order` and `description` the same way.
The separator fix needed a second pass: declaring `id`/`label` optional let a
bare separator through but also waved through an id-less `type: 'object'`
item — caught by two existing assertions in navigation-model.test.ts. A
`superRefine` now re-imposes both for every non-separator type, and a new
assertion pins that boundary so the exemption cannot be widened silently.
NOT changed: the spec models navigation as a discriminated union of nine
variants with per-variant required targets and an exclusivity refinement;
objectui keeps one flat all-optional shape, so it still accepts items the
spec would reject. Converging is a breaking change for every consumer that
reads fields off `NavigationItem` without narrowing — tracked separately.
The four ledger entries stay: spec's `NavigationItemSchema` is declared
`z.ZodType<any>` (its recursive group variant erases the union), so a
re-export would delete all navigation typing. This fixes the drift, not the
name collision.
Mutation-tested: dropping each of the four schema fixes fails its assertion
by name, and disabling the separator refinement fails three. 78/78
type-check; full suite 8932 assertions green.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
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.
接 #4115 分诊里
NavigationItem那一簇(4 条台账)。这一轮修的是实际缺陷,不是命名问题。先说一个改变影响评估的事实
objectui 的 zod schema 在生产代码里只有一条运行时路径:已发布的
objectui validate命令(@object-ui/cli,非 private,bin 名objectui)。渲染器直接读普通对象,从不 parse。所以下面每一条都是 CLI 校验的缺陷 —— 而且因为 schema 是 strip 模式(丢弃未知键而非报错),全部是静默失败。实测出来的六处(spec 17.0.0-rc.0)
requiresObject/requiresService被剥掉actionDef被剥掉 —— 动作项校验通过却什么都不做expanded(spec 拼写)被剥掉badgeVariant: 'secondary'被硬拒{ type: 'separator' }被拒NavigationArea的order/description被丢前两条最值得注意:
requiresObject/requiresService是NavigationItem一直声明着、NavigationRenderer一直在执行的运行时门控。只有 schema 落后 —— 于是校验一个 app,会把它自己 nav 元数据里的门控剥掉。expanded:渲染器早就在读它,代码写的是(item as any).expanded,注释还写着「honor either so app authors don't get silently-ignored config」。作者知道 spec 用这个名字并做了处理,却因为类型没声明而被迫 cast。那个as any现在删掉了。separator 那处我改错了一版,是既有测试拦下的
为放行 spec 合法的
{type:'separator'},第一版把id/label对所有类型改成可选 —— 那会让{type:'object'}这种没有标识的项也通过。navigation-model.test.ts里两条既有断言立刻报红,测试是对的、schema 是错的。改法是用
superRefine把豁免精确限定在 separator(它是一条分隔线,本就没有身份和文案),其余类型照旧必填;并新增一条断言钉住这个边界,免得后人把豁免放宽。刻意没做的事
spec 把导航建模为九个变体的判别联合,每个变体的目标字段必填,外加一条互斥 refinement;objectui 是一个扁平全可选形状,所以仍然接受 spec 会拒绝的项(如
type:'object'而无objectName)。收敛过去会破坏所有不做窄化就直接读NavigationItem字段的消费者 —— 那是独立决策,没有夹带进来。台账不减少,如实说明
这 4 条条目仍在册(124 未变)。 spec 的
NavigationItemSchema声明为z.ZodType<any>(递归的 group 变体让联合类型被擦除),所以 re-export 会删掉全部导航类型信息。本 PR 修的是漂移,不是名字碰撞;要烧掉条目得改NavigationItem的名字,而它是高频公开类型。顺带记一条给 #4115 修法模板的经验:spec 的联合类型擦除成
any时不能 re-export,但它的各个变体类型是完整的 —— 本 PR 的badgeVariant就是从ObjectNavItem派生的,而不是再抄一遍枚举。验证
navigation-spec-parity.test.ts);type-check78/78;🤖 Generated with Claude Code