Repository navigation
fix(react): emit BaseSchema.testId as data-testid (objectui#8268) - #8931
Conversation
`testId` was absent from `SchemaRenderer`'s metadata destructure, so it fell through into the spread and reached the DOM as the non-standard lowercase `testid` that React writes for an unrecognised prop — the attribute the declaration promises was never emitted, and no query helper finds the one that was. Strip the key and re-emit it as `data-testid` beside `data-obj-id`. Spread conditionally: `'data-testid': undefined` would add the key to every node's props bag and overwrite a component's own locator. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01611D6ZaRaMmwTNQmSbk8MH
✅ Console Performance Budget
The eager closure is every chunk the entry reaches through static imports — what the browser fetches and parses before the app renders. The entry chunk on its own is a small fraction of it. 📦 Bundle Size Report
Size Limits
|
|
Tier notice — the contract-review-tier requirement on this PR is lifted (skills seat, session Maintainer ruling, verbatim: 「现有的卡片如果写了要求fable的,也要让相关的项目经理知道,opus就够了。」 Under the same ruling set (quoted in full on objectstack-ai/objectstack#17285), the contract-review tier is reserved for the skills seat (protocol files + the published For this PR: its Generated by Claude Code |
Fixes #8268
BaseSchema.testId's JSDoc promised "Rendered as data-testid attribute." Nothing renderedit. The key was absent from
SchemaRenderer's metadata destructure, so it fell through intothe spread, was handed to the component as a React prop, and reached the DOM under React's
fallback spelling for an unrecognised prop — a non-standard lowercase
testidthatscreen.getByTestId(...)and[data-testid=...]both miss. The zod mirror accepts the key, sothe author got no parse-time warning either.
The measurement
Reproduced on my base
93127bd6fthrough the realui:scroll-arearenderer, node{ id: 'my-scroll', testId: 'my-tid' }, both worlds on the same probe:[data-testid="my-tid"][testid="my-tid"]idid="my-scroll"+data-obj-id="my-scroll"— presentid="my-scroll"+data-obj-id="my-scroll"— presentRoot attributes, before and after:
The
idleg is the firing positive control on the same run: the strip list and the spreadwork as designed, and only this key had no mapping. It is deliberately green in both worlds,
and the source comment on it names the wrong fix it guards against — stopping the leak by
widening the strip list mechanically and sweeping
id(or thedata-obj-*pair emitted fromthe same place) out with it.
Two things the card did not have, measured here:
"spell it as lowercase
testid", i.e. steers them to the attribute that does not work,further from the documented one.
testIdbefore this change(measured: an authored
testId: '${data.x}'was named in its output), because the key was incomponentProps. The strip list is that diagnostic's exclusion list, so stripping the keywould have silently narrowed its coverage.
testIdholds a literal, not predicate source, soit is stripped from the spread and kept in the scan set; a case pins that.
Branch A, and why I departed from objectui#7088
objectui#7088 — the class-mirror,
BaseSchema.hidden— resolved by fixing the declaration anddeclining the renderer change (director ruling 2026-09-01, maintainer 「同意」; 「分化不做」,
Clause-②
no). That is branch B, and it is the strong prior. I took A, and the ruling's ownreasoning is why.
#7088 declined the renderer change because it was 「发布 prop 上的行为变更,零具名消费者」 — a
behaviour change on a published prop with zero named consumers. That premise does not hold
here. Measured on this base, the promise already has carriers outside the type declaration:
content/docs/api/schema-reference.mdstates it as a table row — "Test identifier, renderedas
data-testid." — and authorstestIdin that page's own base-schema example.packages/cli/src/commands/check.ts—OBJECTUI_STRUCTURAL_KEYSidentifies a file as anObjectUI schema node by this key, in a published CLI, with a comment saying the set
"grows only when
BaseSchemagrows".packages/types/src/objectql.ts—ObjectGridSlotKeyandObjectFormSlotKeyboth pin it.packages/core—SchemaBuilder.testId()is a published builder method that writes it.layout/box.mdxstill carries a// Base propertiesblock, so the 16 for that grep isintact, but its block was trimmed to
id/visibleand no longer liststestId.)data-testid… derivedfrom metadata". Retiring the key is a move against a landed ADR.
Two more asymmetries against B:
content/docs/api/schema-reference.md, which this PR is fenced off (objectui#8914 is inflight there). Under B that page keeps a live falsehood this PR cannot fix; under A it
becomes true with no doc edit at all.
hiddenhad a behaviour to describe; this key has none. "Make the declaration honest"here means describing nothing, which is retirement — and retirement crosses
types(decl +zod mirror + two pinned key unions),
core(a published builder method),cli(a publishedmarker list), 15 doc pages and the fenced file, for a p3 finding.
ADR-0049 is enforce-or-remove; this is the enforce arm. AGENTS.md #0.1 is not in tension:
there is no lenient fallback, no alias, no
??-default here — the key isBaseSchema's owndeclaration and it is honoured under its own single spelling.
Triage's third determinate defect (the stray lowercase
testidreaching the DOM whatever isdecided about the promise) is subsumed: the key is now in the strip list.
The one thing that had to be measured, not reasoned
The emission is spread conditionally:
The unconditional
'data-testid': _testIdform was written first and turned 9 tests redacross 5 files, three of them the byte-for-byte props-bag pins (objectui#6708 / #6752 /
#6760). Passing
undefinedis invisible in rendered HTML but puts the key in every node's propsbag, and a component that sets its own
data-testidbefore spreading what it is handed — theADR-0054 C4 shape, common here — has its locator overwritten with
undefinedand loses it. Anode that authors no
testIdis now byte-identical to before this PR, and two cases pin bothsides of that precedence.
Verification
Everything below at
94326f2ddunless stated.pnpm exec vitest run packages/react/src packages/types/src→Test Files 238 passed (238) · Tests 4084 passed (4084)pnpm exec vitest run packages/components/src packages/app-shell/src→Test Files 925 passed (925) · Tests 8825 passed, 1 skipped (8826)(the published-face consumers)pnpm --filter @object-ui/types --filter @object-ui/react run type-check→ bothDone. Coverage of the new file proved, not assumed:tsc -p packages/react/tsconfig.test.json --listFileslistsSchemaRenderer.testIdEmission.test.tsx.turbo run lint --filter=@object-ui/react --filter=@object-ui/types→Tasks: 3 successful, 3 total, 0 errors. Warnings are pre-existingno-explicit-any; none falls on an edited line (SchemaRenderer.tsx warnings stop at 1440, edits are 1477+; no base.ts warning in 415–460; none on the new file).pnpm changeset:check→ 3 assertions pass ·pnpm check:control-bytes→OK (scanned 7113 tracked text file(s))·pnpm check:vi-mock-specifiers→ OK ·pnpm check:shell-escape-residue→ OK ·pnpm check:doc-types→Every documented component type is registered.·pnpm check:doc-fences→ OKgrep -naPfor control bytes over all four diff files → 0 each, with a proven-positive probe.node scripts/check-governed-queue-guard.mjs --test THE-FOUR-PATHS→NOT GOVERNED.Ablation — the pin can actually fail, twice, and the control survives both. Run on the
committed implementation, each leg with its on-disk mutation proved by blob hash and restored
with
git checkout HEAD -- PATHunder atrap, restore proved by an emptygit diff HEADand by the blob returning to
90426f2740737ede85a4ed871b899822ab9b3fd3:data-testidemissionTests 2 failed · 4 passed (6)testIdback in the spread (re-create the leak)Tests 1 failed · 5 passed (6)— the "NOT the lowercase spelling" caseThe
idcontrol was green in all four worlds.pnpm check:doc-snippetsandpnpm check:doc-examplesfirst returned exit 2 =PREREQUISITE NOT MET, which is neither red nor green. Rather than report that, the
prerequisite was satisfied —
turbo run build $(node scripts/check-doc-snippet-types.mjs --build-filter) --concurrency=2→Tasks: 35 successful, 35 total— and both re-run to a realverdict:
pnpm check:doc-snippets→ exit 0,Semantic phase: 638 of 638 block(s) judged, 0 failed.pnpm check:doc-examples→ exit 0,Every covered @example compiles, or fails exactly as its ledger row declares.Consistent with the independent argument that they could not move: their population is
TypeScript fences in documents, this diff changes 0 document files, and
packages/types/src/base.ts's diff is comment-only — every changed line in it is a JSDocline, verified with a probe whose positive control finds the non-comment changed lines in
SchemaRenderer.tsx. No declaration byte moved.验收备注 — measured, deliberately not fixed
content/docs/api/schema-reference.mdline ~90 carries the promise as a table row and line~61 authors
testIdin the base-schema example. Both become correct with this PR and noedit — which is the point — but the file is fenced (objectui#8914). Flagged, not touched.
PIPELINE_KEYSlists (examples/schema-catalog/test/) calltestId"a key the render pipeline handles for EVERY node". That was false before this PR and is true
after it. No edit needed; noted so the next reader knows it was checked, not missed.
testIdauthored in a live schema node — is not met:the only authored occurrence in the tree is the doc JSON example above. Left at p3.
Clause-②
Clause-②: yes, declared on the card's claim comment and carried here. Both branches move apublished face and this one moves the renderer's DOM output on nodes that author
testId— inboth directions, since the accidental
[testid=…]stops matching. The A-vs-B call itself is thecontract-face question the carrier exists for, and this PR is the reviewable increment it is
supposed to go up with.
🤖 Generated with Claude Code
https://claude.ai/code/session_01611D6ZaRaMmwTNQmSbk8MH
Generated by Claude Code