Repository navigation
fix(core): enforce VisuallyHidden's styling-free contract at runtime - #7826
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
There was a problem hiding this comment.
Thanks for tightening this up: stripping xstyle, className and style before the spread keeps a cast style from un-hiding the label and removes the stray xstyle="[object Object]" attribute, and the new test fails on main and passes here. One change is needed first: adding 'xstyle' to the Omit removes a prop the released 0.7.2 VisuallyHiddenProps accepts, so <VisuallyHidden xstyle={...}> stops compiling (TS2322), and the release-compatibility spec (AST-017 FR31 and FR32) allows that only as a [breaking] change in a planned minor, not in this patch [fix]. Please revert that line (optionally re-declaring xstyle with @deprecated) and keep the Changeset scoped to the runtime fix; the type removal can follow as a [breaking] Changeset with a one-line migration once a minor is planned.
[Automated review]
PR Analysis Report📚 Storybook Preview🧪 Sandbox PreviewModified ComponentsVisuallyHidden (@astryxdesign/core) · View in Storybook
Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Visual Regression46 of 486 shot(s) changed. A change here is a question, not a failure: check whether the after is the
and 26 more. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
VisuallyHidden documents itself as styling-free with a non-overridable clip block, but its props only omitted className/style. xstyle stayed accepted by the type and was spread onto the element, where it reaches the DOM as xstyle="[object Object]"; a cast style kept the last word on position and un-hid the node. Add xstyle to the Omit and strip xstyle/className/style off the rest props at runtime, so a cast cannot reach the element either.
Review follow-up on meta#7826. Narrowing `VisuallyHiddenProps` was too far. Released 0.7.2 accepts `xstyle` through `BaseProps`, so taking it off the interface makes `<VisuallyHidden xstyle={…}>` stop compiling — a change that requires every consumer to edit code. AST-017 FR53 says an accessibility behavior fix "never removes, renames, or narrows existing surface" and that a change requiring app edits must be redesigned, and FR31 admits a `[breaking]` Changeset only while `main` declares a minor; it declares 0.7.2, a patch plan, so `pnpm check:changesets` would refuse the tag even if the removal were the right call. `xstyle` is therefore re-declared with `@deprecated`, exactly the compatibility shape the released type had, and the interface removal is left for a planned minor with a one-line migration. What still ships is the runtime fix, and measuring 0.7.2 first is what keeps it a `[fix]`: rendering `<VisuallyHidden xstyle={overrides.tint}>` against main produces `style=null`, computed `position: absolute` and `width: 1px` — the released clip block already won, so no consumer's rendering changes — while the invalid `xstyle="[object Object]"` attribute does reach the DOM. Dropping the three styling props before the spread removes that attribute and closes the cast path that could un-hide the node, which is the accessibility contract this component exists to hold. The new `still accepts a typed xstyle, and ignores it` case is written as a typed prop on purpose: with the reviewed interface in place it fails `tsc` with TS2322 at that line, and with `xstyle` declared it compiles. It is the tripwire against narrowing the surface again early.
1f36a1e to
f6702a5
Compare
aashish254
left a comment
There was a problem hiding this comment.
The requested change is in f6702a557.
'xstyle' is back out of the Omit — the interface keeps the shape released 0.7.2 had — and xstyle is re-declared on VisuallyHiddenProps with @deprecated, documented as ignored. What ships is the runtime strip only, so the Changeset stays [fix] and patch-eligible: measuring main first shows the released clip block already won every property it sets (style=null, computed position: absolute, width: 1px), so the only observable change for a consumer is that xstyle="[object Object]" stops being written into the DOM.
Verified rather than argued: with the narrowing in place the package type-check fails at the typed <VisuallyHidden xstyle={…}> in the suite with the TS2322 you predicted, and with xstyle declared it exits 0 — that test line is now the tripwire against narrowing again before a planned minor. Full detail, including the inherited require-baseprops-passthrough warning and why the interface removal belongs to a [breaking] Changeset later, is in the reply on the inline thread and the PR body's Review follow-up section.
There was a problem hiding this comment.
Thanks for the follow-up: keeping xstyle in VisuallyHiddenProps removes the compile break, and dropping the three styling props at runtime stops a stray style from un-hiding the label, with tests that fail without the fix. Two changes are needed before this can merge:
- The Changeset says that on 0.7.2 the clip block already won and no consumer's rendering changes, but the published 0.7.2 build writes a spread
style={{position: 'static'}}onto the span, which un-hides the label (as the reproduction in your description shows), so please say instead that only astyleorclassNamepassed outside the type stops reaching the element, and state thexstylemigration. - Marking
xstyle@deprecatedin a patch makes this a deprecation under AST-017 FR28, which ships an exact migration command or codemod when the rewrite is mechanical: either add anastryx upgradetransform that removes staticxstylefromVisuallyHidden(like the 0.7.2ListedgeCompensationone) and name it in the marker, docs and Changeset, or drop@deprecatedand keepxstyledocumented as ignored until a minor removes it.
[Automated review]
…prop Two review corrections. @deprecated turns this patch into a deprecation, which AST-017 FR28 lets a patch carry only alongside the exact migration command or codemod for it. The marker is gone; xstyle stays on the interface, documented as ignored, and the removal is left for a planned minor. Threading a codemod through `astryx upgrade` here would widen a two-file component fix into a CLI feature for a prop whose entire documented behavior is that nothing happens. The Changeset's "no consumer's rendering changes" was a generalization from the xstyle arm. Re-measured per prop against main's implementation: xstyle reached the DOM as the attribute alone (style null, same clip classes), className was already displaced by the clip block's class list, and a style arriving outside the type did reach the element as style="position: static;" — an inline declaration outranks the class rules, so that node was un-hidden and now is not. The Changeset says which arm changes pixels and which does not, and names the migration (delete the prop).
aashish254
left a comment
There was a problem hiding this comment.
Both points are addressed in 84327b84b.
The Changeset no longer says what only one arm shows. It generalized the xstyle measurement to "no consumer's rendering changes", which the style path contradicts — and it contradicts it in this PR's own reproduction, so the claim was checkable against the description. The four arms are now measured separately and the Changeset reports them separately: xstyle loses the stray attribute and no pixel, className was already displaced by stylex.props' own class on main and is unchanged here, and style arriving outside the Omit was written inline (style="position: static;"), which outranks the clip classes — that node was un-hidden and now stays hidden. The one rendering change is the one the docstring asks for. The xstyle migration is stated in the Changeset: delete the prop.
@deprecated is gone. You gave two ways out and the cheaper one is the right one here. migrate-list-edge-compensation-to-edge.mjs shows what the first costs — transform module, transforms/v0.7.2/index.mjs registration, a __tests__ file, and a CLI Changeset — all to migrate a prop that applies nothing. xstyle stays declared with the "Ignored" note; the header docstring now names FR28 as the reason the marker is absent so it doesn't get re-added as an oversight, and the interface removal plus the "delete the prop" migration stay with a planned minor, where FR28 needs no deprecation path first.
Gates on 84327b84b: pnpm vitest run --project ui packages/core/src/VisuallyHidden → 9 passed (9); tsc --noEmit in packages/core → exit 0 with a typed xstyle in the suite; check:sync → clean; check-changesets → valid against the 0.7.2 patch plan; eslint → the one warning main's file already raises; checkastryx's 18 checks ran green as the pre-commit hook.
There was a problem hiding this comment.
Thanks for the follow-up: dropping @deprecated and splitting the Changeset prop by prop resolve both earlier requests, and the runtime strip now keeps a spread style from un-hiding the text while a typed xstyle still compiles. Nothing further is needed from you; the remaining step is the engineering owner's code review the repository requires.
[Automated review]
User impact
A consumer who passes
xstyle(or a caststyle) toVisuallyHiddengets two failures at once, neither of them visible in TypeScript until runtime:xstyleis written into the DOM as the literal stringxstyle="[object Object]"— an attribute that means nothing, on a node that is supposed to be invisible.stylebeats the clip block'sposition, so the node the contract calls non-overridable is overridable: the visually-hidden text becomes visible content in normal flow, while still sitting in the accessibility tree (so it is read out twice where it was meant to be silent).This is the primitive every icon-only label and
aria-liveannouncer is built on, so the failure lands on assistive-tech users: the "screen-reader-only" string starts rendering for sighted users, or the announcement container's layout changes underneath a live region. The restoration is what makes the documented "deliberately styling-free" promise actually hold.Problem and solution fit
Why does the defect occur?
VisuallyHiddencollects leftover props with...propsand spreads them straight ontocreateElement. ItsOmitlist removesclassNameandstyle— but notxstyle, the primary styling prop on every other component in this library. Soxstyleis a legal prop that the render path knows nothing about, and React serialises it as[object Object].styleis omitted from the type but not from the runtime, so a cast still delivers it.Why does it harm the task? The component's whole purpose is to be non-visual. Any styling prop that survives to the DOM either corrupts the markup (
xstyle) or competes with the clip block (style, which wins the CSS cascade against a class). Consumers cannot tell the difference between "this component takes no styling" and "this component silently ignores my intent in a way I have to discover by inspectingouterHTML".Why does that harm matter? The contract is already written down — see the authority section — and a published component whose type and runtime disagree with its own docstring is a trap for anyone reading the
.d.tsinstead of the prose.The fix is the runtime end: the three styling props are destructured off the rest props before the spread, so neither a typed
xstylenor a caststylecan reach the element.xstylestays on the interface — declared and documented as ignored, with no@deprecatedmarker — because taking it off makes code that compiles against released 0.7.2 stop compiling, and that is a[breaking]change this repository does not admit whilemaindeclares a patch (spec:AST-017/FR31,FR53). See the review follow-up at the end.Expected behavior and authority
Not a preference — the component's own words, on
main, directly above the props interface (packages/core/src/VisuallyHidden/VisuallyHidden.tsx:21-27):The type on
maincontradicts that sentence one line later (:28-31omits only'className' | 'style'), and the shipped build carries the same gap —packages/core/dist/VisuallyHidden/VisuallyHidden.d.ts:23:So this PR makes the implementation obey the contract the source already documents; it introduces no new promise.
Smallest restoration
Two files,
packages/core/src/VisuallyHidden/only:xstyle,classNameandstyleoff the rest props at runtime before the spread, so the documented invariant holds even for callers who defeat the type.xstyleonVisuallyHiddenPropsitself, documented as ignored, where released 0.7.2 already accepted it throughBaseProps. The interface keeps the shape consumers compile against; the runtime stops honouring it.No new API, no new prop, no visual or interaction change, no default change, no reformatting, no touched sibling file.
classNamewas already dropped by the spread order; it is now dropped explicitly so all three props go through one documented door.Evidence
Reproduction before the change — same props (
xstyle={{color:'red'}} className="consumer-track" style={{position:'static'}}) rendered against the published build ofmain, realouterHTML:Result after the change — same render, source implementation:
xstyleand the inlinestyleare gone; the clip classes are byte-identical, so nothing about the hidden rendering changes.The interface stays as released, measured as a two-arm pair (
npx tsc --project packages/core/tsconfig.json --noEmit), same typed StyleX value in both arms (stylex.create({tint: {color: 'red'}})), same call site —<VisuallyHidden xstyle={overrides.tint}>in this PR's new test:'xstyle'added to theOmit):error TS2322: … Property 'xstyle' does not exist on type 'IntrinsicAttributes & VisuallyHiddenProps'.— the reviewer's point, reproduced;xstyledeclared, documented as ignored): exit 0, matching released 0.7.2, where the prop was accepted throughBaseProps.The test line is therefore the tripwire: narrowing the surface again before a planned minor is a build failure, not a review miss.
What each prop actually did on
main, measured rather than inferred — the four arms below rendered<VisuallyHidden>againstmain's implementation and against this branch in one vitest run (--project ui), readinggetAttributeoff the live node. Same typed props on both sides:main:style/xstyleattributexstyleonlynull/"[object Object]"null/nullclassNameonlynull, andclassis the clip list aloneconsumer-trackappears in neither armstyleonly"position: static;"null"position: static;"/"[object Object]"null/nullSo the pixel claim splits by prop, and the Changeset now splits it the same way.
xstylewas never an attribute the browser styles from, and the clip classes are the same set in both arms (the harness copy's dev-mode class prefix is derived from its file name, so it is the only difference between the two columns), so a consumer passing it loses a stray attribute and no rendering.classNamealready could not reach the element —stylex.props(styles.visuallyHidden)is spread after the consumer props and supplies its ownclass, so the consumer's was overwritten onmaintoo.styleis the one arm that changes what a reader sees: an inlinestyledeclaration outranks the clip block's class rules, so onmainastyle={{position: 'static'}}arriving past theOmitun-hid the node, and here it no longer does. That is the restoration, not a regression — the clip block is what the docstring calls non-overridable.The correction stays a
[fix]underspec:AST-017/FR32because none of the three is styling surface onVisuallyHiddenProps:classNameandstyleare behind itsOmit, so a call site can only hand them over through a cast or an untyped spread, andxstyleis documented as ignored. No typed call site loses an effect it was promised, so there is no released victim, and no coexistence path is required underFR53.Representative unchanged path — the seven tests that predate this PR in
VisuallyHidden.test.tsxpass onmain's implementation and on this branch alike, includingapplies the clip styles that hide it visuallyandpasses through arbitrary BaseProps (id, role, data-*): the a11y pass-throughs (aria-*,role,id,data-*, handlers) and theas/refbehaviour are untouched. Blast radius in this repo is zero by measurement: of 74 files mentioningVisuallyHidden, none passesxstyle,classNameorstyleto it — this only affects external consumers.Regression test / mutation-sensitive proof — both new cases were run against
main's implementation with only the component file reverted:Removing just the runtime strip on this branch (
const props = rest;) reproduces the same two failures, andrestoring it returns
9 passed (9). With the fix:Test Files 1 passed (1) | Tests 9 passed (9).The first test reaches
classNameandstylethrough an untypedRecord<string, unknown>spread, deliberately — those two are off the interface, so the runtime boundary is the only boundary they can cross. The second new test reachesxstyleas a typed prop, so the pair covers both doors.Scope
Testing
npx vitest run --project ui packages/core/src/VisuallyHidden→Tests 9 passed (9); red-at-base arm above (1 failed | 7 passed), failure named to the exact assertion. Dropping the runtime strip (const props = rest;) fails both new cases —× does not forward the styling props its own contract omitsand× still accepts a typed xstyle, and ignores it— and the control returns to9 passedafter the mutant is restored.npx tsc --project tsconfig.json --noEmitinpackages/core→ exit 0, both before and after the rebase.eslinton the changed component: 1 warning,@astryx/require-baseprops-passthroughat the props parameter — andmain's own file emits the same warning at the same rule (…but never forwards it, so the consumer override is silently dropped), reproduced here by linting an untouched copy ofmain's implementation. Nothing in this PR changes that count, and the repo's gate iseslint . --cachewith no--max-warnings, so a warning the rule already raises onmaindoes not block. Making the warning go away would mean threadingxstyleintostylex.props(...), i.e. starting to honour a prop whose contract is that it is ignored.npx prettier --checkon both → clean.pnpm check:sync→✅ All SYNC comments are clean.(theSYNC:header list — doc/test/story/blocks — needs no update: no prop, example, or behaviour described there changed).pnpm check:repo(all 18 checks) ran as the pre-commit hook on this commit → green.fix/visually-hidden-styling-freeatf6702a557, rebased ontoorigin/main(863e167ba), and re-verified green after the rebase (tests andtscabove both run on the rebased head).@astryxdesign/corefix/patch changeset is included, andnode scripts/check-changesets.mjsreports133 changeset(s) valid … main declares 0.7.2 (patch plan). A[breaking]tag on this change would be refused by that same check today.Review follow-up
astracat-botrequested changes on one point, and it is right: adding'xstyle'to theOmitremoves a prop thereleased 0.7.2
VisuallyHiddenPropsaccepts, so<VisuallyHidden xstyle={…}>stops compiling with TS2322, andspec:AST-017/FR53classes an accessibility behavior fix as patch-eligible only when "existing public props, types,exports, tokens and documented usage keep working unchanged" — "it never removes, renames, or narrows existing
surface", and "a change that would require apps to edit code must be redesigned so the component absorbs it, or it
is classified under FR1".
FR31then puts[breaking]behind a declared minor, whichpnpm check:changesetsenforces while
maindeclares0.7.2.Fixed in
f6702a557: theOmitis back to'className' | 'style',xstyleis re-declared onVisuallyHiddenPropswith a description saying it is ignored, the runtime strip is unchanged, andthe Changeset stays a
[fix]scoped to that runtime behavior — it now also names the accessibility contract the fixserves and the measured
mainresult, whichFR53asks a changeset to do.packages/core's type-check passes witha typed
<VisuallyHidden xstyle={…}>in the suite again, and the removal of that interface entry is left as a[breaking]follow-up for whenever a minor is planned, with the one-line migration being "delete the prop".Review follow-up, round two
astracat-botapproved the interface shape and asked for two more corrections on84327b84b, and both are right.xstyle) and generalized it to "no consumer'srendering changes". The
stylearm does change rendering: the published render path writes a caststyle={{position: 'static'}}onto the span, which is the un-hiding this PR's own reproduction shows. The Changesetand the evidence table above now say which prop changes pixels, which loses only an attribute, and which was already
displaced on
main.@deprecatedin a patch is a deprecation. Underspec:AST-017/FR28, a patch may deprecate a surface only whileshipping the exact migration command or codemod with it, because a compatible release "can only prepare a break".
The marker is therefore gone rather than the migration being added:
xstylestays declared and documented asignored, with no new CLI surface, and the removal plus the "delete the prop" migration stay with a planned minor.
Writing an
astryx upgradetransform for a prop whose entire documented behavior is that nothing happens would turna two-file component fix into a CLI feature and a second package's changeset, so the branch took the option the
review offered.
Re-verified on
84327b84b:npx vitest run --project ui packages/core/src/VisuallyHidden→Tests 9 passed (9);npx tsc --project tsconfig.json --noEmitinpackages/core→ exit 0, which is the point of the second new test — atyped
<VisuallyHidden xstyle={…}>still compiles without the marker;pnpm check:sync→ clean;node scripts/check-changesets.mjs→ valid,main declares 0.7.2 (patch plan);eslinton the component → the sameone
@astryx/require-baseprops-passthroughwarningmain's own file emits;pnpm check:reporan green as thepre-commit hook.