Skip to content

fix(types,layout): 导航元数据不再丢掉渲染器本就在用的 spec 字段 (#4115) - #3088

Merged
os-zhuang merged 1 commit into
mainfrom
claude/navigation-item-spec-align
Jul 31, 2026
Merged

fix(types,layout): 导航元数据不再丢掉渲染器本就在用的 spec 字段 (#4115)#3088
os-zhuang merged 1 commit into
mainfrom
claude/navigation-item-spec-align

Conversation

@os-zhuang

Copy link
Copy Markdown
Contributor

接 #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' 被硬拒 接受,枚举从 spec 派生
{ type: 'separator' } 被拒 接受
NavigationAreaorder / description 被丢 保留

前两条最值得注意:

  • 能力门控:requiresObject/requiresServiceNavigationItem 一直声明着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 派生的,而不是再抄一遍枚举。

验证

  • 新增 9 条断言(navigation-spec-parity.test.ts);
  • 变异测试:逐个撤掉四处 schema 修复 → 各自按名报红;把 separator 豁免放宽成无条件 → 新断言与两条既有断言一起报红;
  • 全仓 type-check 78/78;
  • 全量测试 8932 断言绿(766 文件)。

🤖 Generated with Claude Code

…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>
@vercel

vercel Bot commented Jul 31, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
objectui Ignored Ignored Jul 31, 2026 3:02am

Request Review

@github-actions

Copy link
Copy Markdown
Contributor

✅ Console Performance Budget

Metric Value Budget
Main entry (gzip) 27.9 KB 350 KB
Entry file index-BEzNgu1b.js
Status PASS

📦 Bundle Size Report

Package Size Gzipped
app-shell (index.js) 8.26KB 2.99KB
app-shell (runtime-config.js) 7.42KB 2.32KB
app-shell (types.js) 0.01KB 0.04KB
app-shell (urlParams.js) 7.57KB 2.97KB
auth (AuthContext.js) 0.31KB 0.24KB
auth (AuthGuard.js) 1.17KB 0.53KB
auth (AuthProvider.js) 22.10KB 4.37KB
auth (AuthShell.js) 3.49KB 1.40KB
auth (ForgotPasswordForm.js) 12.12KB 3.41KB
auth (LoginForm.js) 17.86KB 5.29KB
auth (PreviewBanner.js) 0.90KB 0.50KB
auth (RegisterForm.js) 6.43KB 2.09KB
auth (SocialSignInButtons.js) 9.60KB 3.89KB
auth (UserMenu.js) 3.40KB 1.22KB
auth (auth-gate-events.js) 1.29KB 0.66KB
auth (authStyles.js) 5.04KB 1.72KB
auth (createAuthClient.js) 35.76KB 9.11KB
auth (createAuthenticatedFetch.js) 4.37KB 1.69KB
auth (index.js) 2.35KB 1.07KB
auth (org-roles.js) 6.66KB 2.78KB
auth (phone-identifier.js) 1.11KB 0.66KB
auth (types.js) 0.59KB 0.35KB
auth (useAuth.js) 4.91KB 0.87KB
auth (useIsWorkspaceAdmin.js) 1.61KB 0.85KB
collaboration (CommentThread.js) 18.38KB 4.49KB
collaboration (LiveCursors.js) 3.17KB 1.27KB
collaboration (PresenceAvatars.js) 3.65KB 1.42KB
collaboration (PresenceProvider.js) 2.79KB 1.13KB
collaboration (index.js) 1.25KB 0.53KB
collaboration (useCommentSearch.js) 1.98KB 0.88KB
collaboration (useConflictResolution.js) 7.75KB 1.86KB
collaboration (useMentionNotifications.js) 1.81KB 0.68KB
collaboration (usePresence.js) 6.33KB 1.84KB
collaboration (useRealtimeSubscription.js) 7.91KB 2.01KB
components (index.js) 472.44KB 103.27KB
core (index.js) 2.16KB 0.78KB
create-plugin (index.js) 9.28KB 2.98KB
data-objectstack (index.js) 136.34KB 34.64KB
fields (index.js) 222.07KB 54.35KB
i18n (LocalizationContext.js) 1.76KB 0.96KB
i18n (currency.js) 1.22KB 0.64KB
i18n (i18n.js) 4.32KB 1.77KB
i18n (index.js) 2.46KB 0.96KB
i18n (pickLocalized.js) 1.70KB 0.83KB
i18n (provider.js) 5.37KB 1.72KB
i18n (useObjectLabel.js) 25.17KB 5.80KB
i18n (useSafeTranslation.js) 3.26KB 1.44KB
layout (index.js) 38.44KB 10.66KB
mobile (MobileProvider.js) 0.92KB 0.49KB
mobile (ResponsiveContainer.js) 0.94KB 0.38KB
mobile (breakpoints.js) 1.51KB 0.70KB
mobile (createOfflineDataSource.js) 5.61KB 1.74KB
mobile (index.js) 1.50KB 0.62KB
mobile (offlineQueue.js) 3.91KB 1.35KB
mobile (pwa.js) 0.97KB 0.49KB
mobile (serviceWorker.js) 1.48KB 0.62KB
mobile (serviceWorkerSource.js) 3.41KB 1.48KB
mobile (useBreakpoint.js) 1.54KB 0.65KB
mobile (useGesture.js) 6.96KB 1.98KB
mobile (useOfflineSync.js) 1.99KB 0.72KB
mobile (usePullToRefresh.js) 2.53KB 0.85KB
mobile (useResponsive.js) 0.71KB 0.42KB
mobile (useResponsiveConfig.js) 1.36KB 0.63KB
mobile (useSpecGesture.js) 4.05KB 1.53KB
mobile (useTouchTarget.js) 1.01KB 0.54KB
permissions (MePermissionsProvider.js) 8.76KB 3.06KB
permissions (PermissionContext.js) 0.31KB 0.25KB
permissions (PermissionGuard.js) 0.89KB 0.45KB
permissions (PermissionProvider.js) 3.67KB 1.12KB
permissions (evaluator.js) 4.41KB 1.44KB
permissions (index.js) 0.91KB 0.41KB
permissions (retry.js) 3.48KB 1.61KB
permissions (store.js) 0.91KB 0.42KB
permissions (useFieldPermissions.js) 1.28KB 0.52KB
permissions (usePermissions.js) 1.55KB 0.71KB
plugin-ai (index.js) 15.71KB 3.79KB
plugin-calendar (index.js) 44.90KB 12.35KB
plugin-charts (index.js) 60.52KB 17.11KB
plugin-chatbot (index.js) 180.09KB 42.72KB
plugin-dashboard (index.js) 111.59KB 28.74KB
plugin-designer (index.js) 210.51KB 42.50KB
plugin-detail (index.js) 221.81KB 54.28KB
plugin-editor (index.js) 2.46KB 1.10KB
plugin-form (index.js) 110.71KB 26.67KB
plugin-gantt (index.js) 162.26KB 39.53KB
plugin-grid (index.js) 182.21KB 48.24KB
plugin-kanban (index.js) 47.82KB 13.18KB
plugin-list (index.js) 103.85KB 24.80KB
plugin-map (index.js) 16.80KB 5.24KB
plugin-markdown (index.js) 13.65KB 4.67KB
plugin-report (index.js) 40.32KB 10.53KB
plugin-timeline (index.js) 25.75KB 7.32KB
plugin-tree (index.js) 8.36KB 2.81KB
plugin-view (index.js) 83.54KB 20.39KB
providers (DataSourceProvider.js) 0.75KB 0.39KB
providers (MetadataProvider.js) 1.37KB 0.59KB
providers (ThemeProvider.js) 1.90KB 0.85KB
providers (UploadProvider.js) 11.71KB 3.53KB
providers (index.js) 0.44KB 0.22KB
providers (types.js) 0.01KB 0.04KB
react-runtime (index.js) 5.67KB 2.37KB
react (LazyPluginLoader.js) 3.77KB 1.33KB
react (SchemaRenderer.js) 19.28KB 6.38KB
react (data-invalidation.js) 5.05KB 2.08KB
react (index.js) 1.02KB 0.55KB
sdui-parser (codegen.js) 4.09KB 1.74KB
sdui-parser (index.js) 3.47KB 1.54KB
sdui-parser (parse.js) 10.04KB 2.82KB
sdui-parser (types.js) 0.29KB 0.24KB
sdui-parser (validate.js) 4.69KB 1.48KB
types (ai.js) 0.20KB 0.17KB
types (api-types.js) 0.20KB 0.18KB
types (app.js) 2.87KB 0.99KB
types (base.js) 0.20KB 0.18KB
types (blocks.js) 0.20KB 0.18KB
types (complex.js) 0.20KB 0.18KB
types (crud.js) 0.20KB 0.18KB
types (data-display.js) 0.20KB 0.18KB
types (data-protocol.js) 0.20KB 0.19KB
types (data.js) 0.20KB 0.18KB
types (designer.js) 1.87KB 0.85KB
types (disclosure.js) 0.20KB 0.18KB
types (error-code.js) 1.54KB 0.88KB
types (feedback.js) 0.20KB 0.18KB
types (field-types.js) 0.20KB 0.18KB
types (form.js) 0.20KB 0.18KB
types (index.js) 2.07KB 0.99KB
types (layout.js) 0.20KB 0.18KB
types (managed-by.js) 0.19KB 0.18KB
types (mobile.js) 0.20KB 0.18KB
types (navigation.js) 0.20KB 0.18KB
types (objectql.js) 0.20KB 0.18KB
types (overlay.js) 0.20KB 0.18KB
types (permissions.js) 0.20KB 0.18KB
types (plugin-scope.js) 0.20KB 0.18KB
types (record-components.js) 0.20KB 0.19KB
types (record-semantics.js) 1.28KB 0.67KB
types (registry.js) 0.20KB 0.18KB
types (reports.js) 0.20KB 0.18KB
types (spec-report.js) 5.05KB 1.93KB
types (system-fields.js) 3.33KB 1.54KB
types (theme.js) 0.20KB 0.18KB
types (ui-action.js) 1.08KB 0.64KB
types (views.js) 0.20KB 0.18KB
types (widget.js) 0.20KB 0.18KB

Size Limits

  • ✅ Core packages should be < 50KB gzipped
  • ✅ Component packages should be < 100KB gzipped
  • ⚠️ Plugin packages should be < 150KB gzipped

@os-zhuang
os-zhuang merged commit 15209ff into main Jul 31, 2026
16 checks passed
@os-zhuang
os-zhuang deleted the claude/navigation-item-spec-align branch July 31, 2026 03:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant