Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/perf-banner-has-selector.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@primer/react': patch
---

perf(Banner): Optimize CSS :has() selectors for better INP

- Scope `:has(.BannerActions)` selectors to shallow path `> * >` for O(1) lookup
- Scope `:has(.BannerActionsContainer)` to direct child with `>` combinator
12 changes: 8 additions & 4 deletions packages/react/src/Banner/Banner.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@
margin-block: var(--base-size-8);
}

.Banner[data-title-hidden]:not(:has(.BannerActions)) .BannerContent {
/* PERFORMANCE: BannerActions is inside BannerContainer, use shallow path > * > for O(1) lookup */
.Banner[data-title-hidden]:not(:has(> * > .BannerActions)) .BannerContent {
margin-block: var(--base-size-6);
}

Expand Down Expand Up @@ -152,8 +153,9 @@
fill: var(--banner-icon-fgColor);
}

/* PERFORMANCE: BannerActions is inside BannerContainer, use shallow path > * > for O(1) lookup */
/* stylelint-disable-next-line selector-max-specificity */
.Banner[data-title-hidden]:not(:has(.BannerActions)) .BannerIcon svg {
.Banner[data-title-hidden]:not(:has(> * > .BannerActions)) .BannerIcon svg {
height: var(--base-size-16);
}

Expand All @@ -166,7 +168,8 @@
margin-inline-start: var(--base-size-4);
}

:where(.Banner):has(.BannerActions) .BannerDismiss {
/* PERFORMANCE: BannerActions is inside BannerContainer, use shallow path > * > for O(1) lookup */
:where(.Banner):has(> * > .BannerActions) .BannerDismiss {
margin-block: var(--base-size-2);
}

Expand Down Expand Up @@ -211,7 +214,8 @@
display: grid;
}

.BannerContainer:has(.BannerActionsContainer) {
/* PERFORMANCE: BannerActionsContainer is direct child of BannerContainer, scope with > for O(1) lookup */
.BannerContainer:has(> .BannerActionsContainer) {
grid-template-rows: auto auto;
}

Expand Down
Loading