Skip to content

Conversation

@mattcosta7
Copy link
Contributor

@mattcosta7 mattcosta7 commented Dec 15, 2025

Summary

Performance optimization for ButtonGroup CSS selector to improve INP.

Changes

Scope :has(div:last-child:empty) to direct child with > combinator.

Expected INP Impact

Scenario Before After Improvement
Worst case (ButtonGroup in complex layout) ~10-20ms style recalc <2ms 80-90% reduction
Average case (typical ButtonGroup) ~5-10ms style recalc <1ms 80-90% reduction
Best case (simple ButtonGroup) ~2-5ms style recalc <1ms ~75% reduction

Why this matters

The original selector scanned the entire subtree looking for an empty div. ButtonGroup interactions (hover, focus) trigger style recalc. By scoping to direct children, we get O(1) lookup.


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

@changeset-bot
Copy link

changeset-bot bot commented Dec 15, 2025

🦋 Changeset detected

Latest commit: e497cb2

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
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.

@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 github-actions bot temporarily deployed to storybook-preview-7328 December 15, 2025 15:03 Inactive
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