Repository navigation
refactor(schema-catalog): 103 个 div 节点的布局意图改写成 flex/stack/container/grid props (#4003) - #4892
Conversation
…des (#4003) 106 of the catalog's 189 `div` nodes hand-wrote in Tailwind exactly what `flex` / `stack` / `container` / `grid` already expose as declared props. 103 are converted here; the remaining three are documented exemptions. flex 84 items-*/justify-*/gap-N -> align/justify/gap stack 8 space-y-N -> gap container 6 max-w-*/mx-auto -> maxWidth/centered/padding grid 5 (sm|md|lg):grid-cols-N -> columns object + gap Every conversion was verified by rendering the converted node and the `div` it replaced through the real SchemaRenderer around the same children: all 103 subtrees are byte-identical. The only class deltas are the CSS initial values the renderers state explicitly (`flex-row`, `justify-start`, `items-stretch`, `gap-0`, `p-0`, `w-full`), the explicit single-column grid base (`grid-cols-1`), and the mobile-first gap ladder that `FlexSchema.gap` means. Two renderer reads blocked the conversion and are fixed with it: `flex.tsx` read `schema.gap || 2` and `container.tsx` read `schema.padding || 4`, so a declared `0` was folded into the default and the `gap === 0 && 'gap-0'` / `padding === 0 && 'p-0'` branches below were unreachable. Both now use `??`, matching sibling `stack.tsx` / `grid.tsx`. No node in the repository declared either key as `0` before this change. Co-authored-by: Claude <noreply@anthropic.com>
附录:103 个节点的转换清单(文件 → 原 className → 新 props)每行的 n 是该文件内完全相同的转换重复次数(例如 document-browser 的 20 个列表项写法一字不差)。 block-schema/block-marketplace-listing.json (1 node)
block-schema/block-with-variable-overrides-analytics-feature.json (1 node)
block-schema/block-with-variable-overrides-security-feature.json (1 node)
block-schema/feature-card-block.json (1 node)
components-complex-carousel/photo-gallery.json (4 nodes)
components-complex-filter-builder/search-interface.json (1 node)
components-complex-resizable/horizontal-split.json (2 nodes)
components-complex-scroll-area/chat-messages.json (31 nodes)
components-complex-scroll-area/document-browser.json (20 nodes)
components-complex-scroll-area/horizontal-scroll.json (10 nodes)
components-complex-scroll-area/short-150px.json (1 node)
components-complex-scroll-area/tall-300px.json (1 node)
components-data-display-statistic/sales-dashboard.json (1 node)
components-feedback-toaster/with-toast-trigger.json (1 node)
components-form-calendar/form-integration.json (1 node)
components-form-file-upload/form-example.json (1 node)
components-form-toggle/settings-example.json (1 node)
components-layout-semantic/complete-layout.json (1 node)
ecommerce/order-summary.json (2 nodes)
ecommerce/product-card.json (1 node)
ecommerce/product-grid.json (6 nodes)
ecommerce/shopping-cart.json (2 nodes)
marketing/features-grid.json (8 nodes)
marketing/pricing-table.json (2 nodes)
marketing/testimonials.json (2 nodes)
Generated by Claude Code |
✅ Console Performance Budget
📦 Bundle Size Report
Size Limits
|
|
【PM 验收 · ACCEPT,越界核准】objectui 分片 PM(session_01GTRjn8xBqp75dk7kFupVRt)对 #4003(catalog 106 布局节点转 props)的实施验收: 实物核验:30 文件 —— catalog 26 + components 侧恰为两行 越界裁定(A 案核准,留否决窗):flex/container 两行 卡内指引三处出入全部如实修正:4 个 body 节点实不在 106 内(改前瞻守卫 + 真标本反证 17→0 字节静默清零)、grid 非逐字节(多一个 grid-cols-1 是裸 grid 隐式基线,正确)、padding:0 手段自身失效(即越界的成因)。三组反向验证逐字命中预判。CI:19/19 全部完成零失败(dev 终报,PM 采信其逐项清单)。新 findings #4889/#4890/#4891(后两者文件面重叠建议合并 sweep,本 PR 建的棘轮即落点)记账合格,留分诊。 处置:undraft + auto-merge(SQUASH)。 Generated by Claude Code |
Fixes #4003
Part of #3965
基
origin/main@372d9f9b4。前置核查(两项,均已确认)
#4001 已落 main ——
34a00bf29 fix(schema-catalog): grid 示例的列数键 cols → columns (#4001) (#4008)。本单基于其结果动工,新增的 5 个 grid 节点一律写声明键columns,#4001 留下的grid-columns-key.test.tsx全程绿。106 节点清单按 origin/main 重扫对账 —— 与 PR #3998 的判定表逐格一致,catalog 一周内无增删影响:189 个
div节点 / 47 个文件 / 全目录 423 个示例,四类计数 flex 84、stack 9、container 8、grid 5,合计 106。差异为零。转换结果:106 判定 → 103 转换 + 3 豁免
flex(含flex不含flex-col)align/justify/gap/wrapstack(space-y-*)gapcontainer(max-w-*)maxWidth/centered/paddinggrid(grid/grid-cols-*)columns对象 +gap转换后 catalog 的
div节点从 189 降到 86,含div的文件从 47 降到 28。3 个豁免(逐个有据,并写进测试的 allowlist)
components-basic-div/custom-card(2 节点) ——content/docs/components/basic/div.mdx的 "Legacy Examples (For Reference Only)" 两个示例之一,存在的意义就是展示废弃写法,转换等于把该文档页要讲的东西删掉。任何 examples/schema-catalog: 48 个示例仍用已废弃的div组件类型,docs 站每张缩略图都刷一条 deprecation warning #3965 终态下永久豁免(PR fix(components): div 废弃提示每次模块加载只报一次;catalog 换类型那一半升级待定夺 (#3965) #3998 评论在案)。卡内点名的另一个nested-divs全是纯装饰盒,本就不在 106 内。components-layout-page/documentation-page(1 节点,prose prose-slate max-w-none) ——max-w-none是取消最大宽度(抵消 typography 插件自带的),与container.maxWidth施加约束语义相反;且没有任何maxWidth值渲染得出它:ContainerSchema为「无约束」声明了false,但container.tsx:20读的是schema.maxWidth || 'xl',false被折成max-w-xl。强转会改渲染,故不转,已另立ContainerSchema.maxWidth: false是声明了却读不到的值 ——container.tsx用||把它折成max-w-xl#4889。卡内 4 个
body节点:前提不成立,已改为前瞻性防护卡内列的第一个坑是「4 个节点用
body而非children,先改body再换类型」。按 origin/main 重扫,这 4 个节点不在本单范围内 —— 它们是components-basic-sidebar/*.json的四个{"type":"div","className":"p-4","body":[...]},className 只有p-4,落在 PR3998 判定表的「纯装饰盒子 61」里,属于 83 个无对等物那批。本单 103 个转换节点里body键出现 0 次,body→children改写数因此是 0,不是漏做。坑本身是真的,只是命中面在别处。所以没有强行凑一个改写,而是把它钉成面向整个类型族的前瞻守卫:
flex/stack/grid/container一律不得携带body键。下一轮 sweep 处理那 83 个时,naive 换类型会当场撞红而不是静默丢内容(反向验证已实测,见下)。两处渲染器读法修复(本 PR 越出了卡内文件面,单独声明)
卡内给 container 的等价办法是「默认 padding 4,需显式
padding: 0保等价」。实测该办法本身失效:FlexSchema.gap/ContainerSchema.padding都声明为number,0是合法值,但||把它折进默认值 —— 于是两个渲染器里各自那行专门为零值写的分支是死代码:后果实测:声明
padding: 0的 container 渲染出p-2 sm:p-3 md:p-4(6 个 container 节点凭空长出内边距,其中 4 个是 ecommerce / marketing 文档页的顶层包装),声明gap: 0的 flex 渲染出gap-1.5 sm:gap-2。这就是 #4001 的同型故障往下一层:声明了的键,引擎默默丢弃,JSON 说一套 DOM 做一套。两行改为
??,与同族的stack.tsx:25/grid.tsx:88本来就用的读法一致 —— 不是新发明的约定,是把跑偏的两个收回来。未声明该键时默认值一字不变(gap: 2/padding: 4);只有显式声明的0会变,而基线 commit 上全仓 JSON 声明gap: 0或padding: 0的节点数是 0,所以今天渲染的任何东西都不改变。为什么放进本 PR 而不是拆单:不修则卡内的 container 验收条款无法达成,而唯一的绕法是在 className 里塞
p-0 sm:p-0 md:p-0去对冲自己声明的padding—— 正是卡里 ⛔ 掉的「自相矛盾的授权」。若维护者认为该走独立单,回退这 2 行 + 对应 pin 测试即可,代价是本 PR 需撤下 6 个 container 节点、49 个 flex 节点改回不声明gap。等价验证:103/103 渲染子树逐字节一致
把每个转换后的节点、与它替换掉的那个
div(用转换前的真实 className、包住同一批 children)双双送进真的SchemaRenderer渲染后比对。逐节点隔离比较,不比整棵子树 —— 否则差异只会来自后代也被转换了。103 个节点的
innerHTML全部逐字节相同。 类名增减的全集(按 token 统计出现节点数)只有下面这些,没有一项是回归:flex-rowdiv加flex本来就是 rowjustify-startflex-start,原本没写items-stretchitems-*(15 flex + 8 stack)gap-0p-0w-fullwidth:auto已铺满,等效(另 4 个 container 原本就带w-full)grid-cols-1md:grid-cols-*之类响应式列类的裸grid,基础断点本就解析成单列flexflex-colspace-y-*的块级间距换成 flex columngap-2sm:gap-3等)gap-3gap-2 sm:gap-3(mobile-first 阶梯)space-y-4/space-y-2/space-y-3/space-y-6前 8 行全部是无渲染差异的显式化:要么是 CSS 初始值被写明,要么是原本就没有的属性被声明成零。真正改变渲染的只有最后一类 —— gap/space-y 换成阶梯。
gap 阶梯在 640px 以下不是逐字节等价,这是正确语义 —— 阶梯就是
FlexSchema.gap的含义。⛔ 没有用「gap: 0+ className 留着gap-3」去硬凑逐字节:那种写法自相矛盾,而且恰好再教一遍本单要消除的反模式。grid 一类卡内写的是「逐字节等价」,实测略有出入且出入是对的:5 个节点原本都只有响应式列类(
md:grid-cols-3之类)、没有基础列类,渲染器必然产出一个基础列类,于是 5 个各多出一个grid-cols-1;其余 token 逐字节同序。多出来的正是裸grid隐式解析出的单列基线。反向验证(三组,均先写预判再执行)
RV1 —— 渲染器读法。 把
flex.tsx的??改回||。预判:gap-0钉子翻红、features-grid 等价钉翻红,而「省略 gap 时仍默认 2」应当保持绿(||与??在键缺席时一致)。实测与预判一致:17 个通过的里就含「省略 gap 时仍默认 2」 —— 预判的不变方向也确认了(这条正是
??正确、||不正确的分界)。RV2 ——
body陷阱守卫。 卡内预设的靶子(范围内的 body 转 children 转换)不存在,故改用真实标本反向验证守卫本身:取范围外的components-basic-sidebar/basic-sidebar.json的 body 节点,naive 换成flex。预判:body守卫翻红,且内容静默丢失。实测一致:内容丢失实测(同一节点两种 type 渲染):
div的 innerHTML 是"Main content area"(17 字节),flex的是""(0 字节)—— 静默清零,没有任何报错。RV3 —— 反模式棘轮。 把
marketing/testimonials的 grid 节点改回div原写法。预判:棘轮翻红。实测一致:三组变异均已
git checkout还原(⛔ 未用git stash—— stash 栈是跨 worktree 共享的)。新增测试
examples/schema-catalog/test/layout-props-conversion.test.tsx(13 条),沿fields-form-hosted的 harness 形态,钉三件不同的事:div携带布局意图 className,除上述 3 个豁免;另有一条「豁免仍然命中」的反向条款,防止 allowlist 比事实更宽。flex/stack/grid/container节点携带body键(即上文的前瞻守卫);外加非空性下限(当前 441 个布局节点)。packages/components/src/__tests__/layout-zero-scale-values.test.tsx(6 条)钉住零值可达:gap: 0得gap-0、padding: 0得p-0;并各配一条「省略时仍取默认值」(防止把||的 bug 修成反向的 bug)与一条非零阶梯不受影响。验证
全部重活都在
flock /tmp/os-heavy-verify.lock里串行执行,堆上限 4GB。changeset
catalog 侧不欠 changeset:
@object-ui/example-schema-catalog命中.changeset/config.json的ignore项@object-ui/example-*,changesets 从不给它发版。node scripts/check-changeset-presence.mjs实测:但
packages/components的两行读法修复动的是已发版包,故补了.changeset/tidy-poems-shave.md,按 AGENTS.md 版本策略标minor(⛔ 不标major)。边界
只动了 25 个 catalog JSON + 2 个渲染器读法 + 2 个测试 + 1 个 changeset。没有碰 83 个无对等物节点、
div.mdx的 2 个 legacy 示例、任何 MDX 文档页,没有碰content/docs/releases/,没有给渲染器加任何宽容别名。浏览器抽查
未做。容器内没有可用的 preview / 浏览器通道,如实记录:以上述 103/103 的真实
SchemaRendererDOM 断言代替,该断言比缩略图目视更严(逐字节比对子树 + 类名逐字面钉死)。相邻发现(已另立单,不在本 PR 扩围)
三条都打了
finding(今天都没有用户撞到),交分诊定级;三条都做过关键词 + 文件路径的重复检索,无既有单。ContainerSchema.maxWidth: false是声明了却读不到的值 ——container.tsx用||把它折成max-w-xl#4889 ——ContainerSchema.maxWidth声明了false这一档,但container.tsx:20用|| 'xl'读它,false渲染出max-w-xl。本族里剩下的最后一处假值读法,没有跟着本 PR 一起改:它不像gap/padding那样有现成的目标分支,「不产出 max-width 类」与max-w-none是否等价是个需要拍板的设计问题。上面那个documentation-page豁免修好后可回收。stack渲染器读一个从未声明的spacing键,catalog 里 135 个节点照着它写 #4890 ——stack.tsx:25读一个StackSchema从未声明的spacing键((schema as any).spacing),catalog 里 135 个节点、39 个文件照着它写。examples/schema-catalog: 13 个 grid 示例用了未声明的cols键,列数被静默丢弃 —— 要 3/4 列的示例在 docs 站实际渲染成 2 列 #4001 的宽容变体:consumer 接住了所以渲染正确,错写法就一直传播;flex不读这个键,哪天有人把stack换flex就是完整重演。flex/stack/container的节点,仍在 className 里手写自己已声明的 props #4891 —— 140 个节点(33 文件)已经是flex/stack/container,却仍把自己声明的 props 手写在 className 里({"type":"flex","className":"items-center justify-between …"})。与本单同一条立论、不同一批节点:本单管「类型都错」的,这条管「类型对了、props 没用」的。与stack渲染器读一个从未声明的spacing键,catalog 里 135 个节点照着它写 #4890 文件面高度重叠,建议合并成一次 sweep;本 PR 建的棘轮就是它的落点。完整的 103 节点转换清单(文件 → 原 className → 新 props)见下方评论,避免正文过长。
Generated by Claude Code