Skip to content

fix(core): enforce VisuallyHidden's styling-free contract at runtime - #7826

Merged
imdreamrunner merged 4 commits into
meta:mainfrom
aashish254:fix/visually-hidden-styling-free
Oct 23, 2026
Merged

imdreamrunner merged 4 commits into
meta:mainfrom
aashish254:fix/visually-hidden-styling-free

Conversation

@aashish254

@aashish254 aashish254 commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

User impact

A consumer who passes xstyle (or a cast style) to VisuallyHidden gets two failures at once, neither of them visible in TypeScript until runtime:

  • xstyle is written into the DOM as the literal string xstyle="[object Object]" — an attribute that means nothing, on a node that is supposed to be invisible.
  • An inline style beats the clip block's position, 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-live announcer 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? VisuallyHidden collects leftover props with ...props and spreads them straight onto createElement. Its Omit list removes className and style — but not xstyle, the primary styling prop on every other component in this library. So xstyle is a legal prop that the render path knows nothing about, and React serialises it as [object Object]. style is 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 inspecting outerHTML".

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.ts instead 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 xstyle nor a cast style can reach the element. xstyle stays on the interface — declared and documented as ignored, with no @deprecated marker — 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 while main declares 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):

VisuallyHidden is deliberately styling-free: it exists to not be seen, so it intentionally omits xstyle/className/style. The clip block is fixed and non-overridable — styling a visually-hidden node is always a mistake.

The type on main contradicts that sentence one line later (:28-31 omits only 'className' | 'style'), and the shipped build carries the same gap — packages/core/dist/VisuallyHidden/VisuallyHidden.d.ts:23:

export interface VisuallyHiddenProps extends Omit<BaseProps<HTMLElement>, 'className' | 'style'> {

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:

  1. Strip xstyle, className and style off the rest props at runtime before the spread, so the documented invariant holds even for callers who defeat the type.
  2. Declare xstyle on VisuallyHiddenProps itself, documented as ignored, where released 0.7.2 already accepted it through BaseProps. 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. className was 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 of main, real outerHTML:

    <span xstyle="[object Object]" class="x10l6tqk x1i1rx1s xjm9jq1 xkdpibf x1717udv xb3r6kr xzpqnlu xuxw1ft xng3xce x13vifvy x1o0tod x47corl x87ps6o" style="position: static;">Hidden</span>
  • Result after the change — same render, source implementation:

    <span class="VisuallyHidden__styles.visuallyHidden x10l6tqk x1i1rx1s xjm9jq1 xkdpibf x1717udv xb3r6kr xzpqnlu xuxw1ft xng3xce x13vifvy x1o0tod x47corl x87ps6o">Hidden</span>

    xstyle and the inline style are 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:

    • against the interface as this branch first shipped it ('xstyle' added to the Omit): error TS2322: … Property 'xstyle' does not exist on type 'IntrinsicAttributes & VisuallyHiddenProps'. — the reviewer's point, reproduced;
    • against the interface as it now stands (xstyle declared, documented as ignored): exit 0, matching released 0.7.2, where the prop was accepted through BaseProps.

    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> against main's implementation and against this branch in one vitest run (--project ui), reading getAttribute off the live node. Same typed props on both sides:

    props passed main: style / xstyle attribute this branch
    xstyle only null / "[object Object]" null / null
    className only null, and class is the clip list alone the same clip list; consumer-track appears in neither arm
    style only "position: static;" null
    all three "position: static;" / "[object Object]" null / null

    So the pixel claim splits by prop, and the Changeset now splits it the same way. xstyle was 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. className already could not reach the element — stylex.props(styles.visuallyHidden) is spread after the consumer props and supplies its own class, so the consumer's was overwritten on main too. style is the one arm that changes what a reader sees: an inline style declaration outranks the clip block's class rules, so on main a style={{position: 'static'}} arriving past the Omit un-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] under spec:AST-017/FR32 because none of the three is styling surface on VisuallyHiddenProps: className and style are behind its Omit, so a call site can only hand them over through a cast or an untyped spread, and xstyle is 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 under FR53.

  • Representative unchanged path — the seven tests that predate this PR in VisuallyHidden.test.tsx pass on main's implementation and on this branch alike, including applies the clip styles that hide it visually and passes through arbitrary BaseProps (id, role, data-*): the a11y pass-throughs (aria-*, role, id, data-*, handlers) and the as / ref behaviour are untouched. Blast radius in this repo is zero by measurement: of 74 files mentioning VisuallyHidden, none passes xstyle, className or style to 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:

    × does not forward the styling props its own contract omits
    × still accepts a typed xstyle, and ignores it
    Test Files  1 failed (1) | Tests 2 failed | 7 passed (9)
    

    Removing just the runtime strip on this branch (const props = rest;) reproduces the same two failures, and
    restoring it returns 9 passed (9). With the fix: Test Files 1 passed (1) | Tests 9 passed (9).

    The first test reaches className and style through an untyped Record<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 reaches xstyle as a typed prop, so the pair covers both doors.

Scope

  • One defect is restored.
  • Separable contradictory or unsettled tagalongs were removed or split.
  • No new public API, visual representation, default, or interaction model is hidden under the bug-fix label.
  • Public text and artifacts contain no internal Meta context.

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 omits and × still accepts a typed xstyle, and ignores it — and the control returns to 9 passed after the mutant is restored.
  • npx tsc --project tsconfig.json --noEmit in packages/core → exit 0, both before and after the rebase.
  • eslint on the changed component: 1 warning, @astryx/require-baseprops-passthrough at the props parameter — and main'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 of main's implementation. Nothing in this PR changes that count, and the repo's gate is eslint . --cache with no --max-warnings, so a warning the rule already raises on main does not block. Making the warning go away would mean threading xstyle into stylex.props(...), i.e. starting to honour a prop whose contract is that it is ignored.
  • npx prettier --check on both → clean.
  • pnpm check:sync → ✅ All SYNC comments are clean. (the SYNC: 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.
  • Branch is fix/visually-hidden-styling-free at f6702a557, rebased onto origin/main (863e167ba), and re-verified green after the rebase (tests and tsc above both run on the rebased head).
  • No changeset-free merge risk: a @astryxdesign/core fix/patch changeset is included, and node scripts/check-changesets.mjs reports 133 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-bot requested changes on one point, and it is right: adding 'xstyle' to the Omit removes a prop the
released 0.7.2 VisuallyHiddenProps accepts, so <VisuallyHidden xstyle={…}> stops compiling with TS2322, and
spec:AST-017/FR53 classes 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". FR31 then puts [breaking] behind a declared minor, which pnpm check:changesets
enforces while main declares 0.7.2.

Fixed in f6702a557: the Omit is back to 'className' | 'style', xstyle is re-declared on
VisuallyHiddenProps with a description saying it is ignored, the runtime strip is unchanged, and
the Changeset stays a [fix] scoped to that runtime behavior — it now also names the accessibility contract the fix
serves and the measured main result, which FR53 asks a changeset to do. packages/core's type-check passes with
a 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-bot approved the interface shape and asked for two more corrections on 84327b84b, and both are right.

  • The Changeset overclaimed. It carried a single measured arm (xstyle) and generalized it to "no consumer's
    rendering changes". The style arm does change rendering: the published render path writes a cast
    style={{position: 'static'}} onto the span, which is the un-hiding this PR's own reproduction shows. The Changeset
    and the evidence table above now say which prop changes pixels, which loses only an attribute, and which was already
    displaced on main.
  • @deprecated in a patch is a deprecation. Under spec:AST-017/FR28, a patch may deprecate a surface only while
    shipping 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: xstyle stays declared and documented as
    ignored, with no new CLI surface, and the removal plus the "delete the prop" migration stay with a planned minor.
    Writing an astryx upgrade transform for a prop whose entire documented behavior is that nothing happens would turn
    a 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 --noEmit in packages/core → exit 0, which is the point of the second new test — a
typed <VisuallyHidden xstyle={…}> still compiles without the marker; pnpm check:sync → clean;
node scripts/check-changesets.mjs → valid, main declares 0.7.2 (patch plan); eslint on the component → the same
one @astryx/require-baseprops-passthrough warning main's own file emits; pnpm check:repo ran green as the
pre-commit hook.

@vercel

vercel Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
astryx Ready Ready Preview Oct 21, 2026 8:47pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 21, 2026
@astracat-bot

astracat-bot Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Oct 23, 2026, 5:45 PM UTC

@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge labels Oct 21, 2026
aashish254 added a commit to aashish254/astryx that referenced this pull request Oct 21, 2026

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR

🧪 Sandbox Preview

View Sandbox for this PR

Modified Components

VisuallyHidden (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 58 -
Complexity N/A Low (2) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.9KB 1.2KB

Accessibility Audit

Status: No accessibility violations detected.

Visual Regression

46 of 486 shot(s) changed.

A change here is a question, not a failure: check whether the after is the
picture you intended. Record that review on the PR. Baseline maintenance is an
explicit dispatch of CI; this report never rewrites the baseline or adds a release gate.

component story theme mode pixels
Selector Indicator Space Bottom Sheet Narrow End RTL neutral light 753,933
Selector Indicator Space Bottom Sheet Wide Start neutral light 740,072
Chat Full AI Chat probe light 230,823
Chat Full AI Chat probe dark 229,805
RichTextEditor Markdown parity: side by side probe dark 94,866
RichTextEditor Markdown parity: side by side probe light 89,762
Collapsible Dividers probe dark 66,445
Collapsible Dividers probe light 66,445
Chat Default neutral dark 36,304
Chat Default neutral light 35,767
Chat Empty State probe light 23,531
Chat Empty State probe dark 22,622
ChatAutoScroll Scroll Behavior Comparison neutral dark 15,378
ChatAutoScroll Scroll Behavior Comparison neutral light 14,107
Chat With Attachments probe light 13,406
Chat With Attachments probe dark 11,232
ProgressBar With Target Mark probe dark 7,895
ProgressBar With Target Mark probe light 7,895
Markdown Default neutral dark 7,573
Markdown Default neutral light 7,566

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.
@aashish254
aashish254 force-pushed the fix/visually-hidden-styling-free branch from 1f36a1e to f6702a5 Compare October 21, 2026 19:39

@aashish254 aashish254 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 a style or className passed outside the type stops reaching the element, and state the xstyle migration.
  • Marking xstyle @deprecated in 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 an astryx upgrade transform that removes static xstyle from VisuallyHidden (like the 0.7.2 List edgeCompensation one) and name it in the marker, docs and Changeset, or drop @deprecated and keep xstyle documented 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 aashish254 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]

@github-actions github-actions Bot removed the needs:code-review High-risk change (new package/component/API) — needs human code review before merge label Oct 23, 2026
@imdreamrunner
imdreamrunner merged commit 3001ed5 into meta:main Oct 23, 2026
64 checks passed

This branch was successfully deployed

1 active deployment
Preview — 84327b84 Deployed Oct 21, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. community Authored by a community contributor (not on the eng/design team)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants