Skip to content

perf(ButtonGroup): Scope :has() selector to direct child for O(1) lookup#7328

Closed
mattcosta7 wants to merge 2 commits intomainfrom
perf/buttongroup-has-selector
Closed

perf(ButtonGroup): Scope :has() selector to direct child for O(1) lookup#7328
mattcosta7 wants to merge 2 commits intomainfrom
perf/buttongroup-has-selector

Conversation

@mattcosta7
Copy link
Copy Markdown
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
Copy Markdown

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
Copy Markdown
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
@github-actions
Copy link
Copy Markdown
Contributor

Hi! This pull request has been marked as stale because it has been open with no activity for 60 days. You can comment on the pull request or remove the stale label to keep it open. If you do nothing, this pull request will be closed in 7 days.

@github-actions github-actions bot added the Stale label Feb 17, 2026
@github-actions github-actions bot closed this Feb 24, 2026
@github-actions github-actions bot deleted the perf/buttongroup-has-selector branch February 24, 2026 16:25
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 Stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant