Skip to content

Conversation

@mattcosta7
Copy link
Contributor

@mattcosta7 mattcosta7 commented Dec 15, 2025

Summary

Performance optimizations for Button CSS selectors to improve INP.

Changes

  • Replace :has(.Visual) selectors with [data-no-visuals] attribute checks
  • Added documentation comments explaining acceptable :has() usage patterns

Expected INP Impact

Scenario Before After Improvement
Worst case (many buttons on page, rapid interactions) ~15-30ms style recalc per button <2ms 85-95% reduction
Average case (typical button usage) ~5-15ms style recalc <1ms 80-90% reduction
Best case (single button interaction) ~3-8ms style recalc <1ms 70-85% reduction

Why this matters

Button is one of the most frequently used components. Every hover, focus, and click triggers style recalculation. The :has(.Visual) selector was forcing descendant scans on every single button interaction. Data attribute checks are O(1).


Part of the INP performance optimization effort. See #7312 for full context.

Replace :has(.Visual) selectors with [data-no-visuals] attribute checks to avoid descendant DOM scans.
Added documentation comments explaining acceptable :has() usage patterns.

Part of #7312
@changeset-bot
Copy link

changeset-bot bot commented Dec 15, 2025

🦋 Changeset detected

Latest commit: a6617a3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm label Dec 15, 2025
@github-actions
Copy link
Contributor

👋 Hi, this pull request contains changes to the source code that github/github-ui depends on. If you are GitHub staff, test these changes with github/github-ui using the integration workflow. Or, apply the integration-tests: skipped manually label to skip these checks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants