Skip to content

Conversation

@mattcosta7
Copy link
Contributor

@mattcosta7 mattcosta7 commented Dec 15, 2025

Summary

Remove expensive :has([data-color-mode]) selectors that scanned the entire DOM on every style recalculation.

Changes

Removed redundant CSS rules that used :has([data-color-mode='light']) and :has([data-color-mode='dark']) selectors. Input color-scheme is already handled by global selectors in the codebase.

Expected INP Impact

Scenario Before After Improvement
Worst case (large DOM, 10k+ nodes) ~100-200ms style recalc 0ms (removed) 100% reduction
Average case (typical page, 1-5k nodes) ~30-80ms style recalc 0ms (removed) 100% reduction
Best case (small page) ~10-20ms style recalc 0ms (removed) 100% reduction

Why this matters

These were the most expensive selectors in the entire codebase:

  • :has([data-color-mode]) on the root element forces a full DOM traversal
  • Fires on every single style recalculation across the entire page
  • Completely redundant as the functionality is handled elsewhere

This single change likely has the highest INP impact of all the optimizations.


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

Remove :has([data-color-mode]) selectors that scanned the entire DOM on every style recalculation.
Input color-scheme is already handled by global selectors.

Part of #7312
@changeset-bot
Copy link

changeset-bot bot commented Dec 15, 2025

🦋 Changeset detected

Latest commit: 7f0a23b

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.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR removes performance-impacting CSS selectors from BaseStyles that were causing expensive DOM traversals during style recalculation. The removed :has([data-color-mode]) selectors scanned the entire DOM tree unnecessarily, as the input color-scheme functionality is already handled by existing global selectors elsewhere in the codebase.

Key Changes:

  • Removed redundant :has([data-color-mode='light']) and :has([data-color-mode='dark']) selectors
  • Added explanatory comment documenting why the selectors were removed and where the functionality is handled
  • Added changeset documenting the performance improvement

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
packages/react/src/BaseStyles.module.css Removed expensive :has() selectors and replaced with explanatory comment
.changeset/perf-basestyles-has-selector.md Added changeset documenting the performance optimization

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