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
5 changes: 5 additions & 0 deletions .changeset/perf-css-bucketable-selectors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': patch
---

Improve style-recalc performance by making ButtonGroup, DataTable Pagination, and Checkbox CSS selectors bucketable (removing universal `*`/`:not([attr])` subjects and `:is()` selector-list merges)
2 changes: 1 addition & 1 deletion packages/react/src/ButtonGroup/ButtonGroup.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
vertical-align: middle;
isolation: isolate;

& > *:not([data-loading-wrapper]) {
& > .Item {
/* stylelint-disable-next-line primer/spacing */
margin-inline-end: -1px;
position: relative;
Expand Down
6 changes: 5 additions & 1 deletion packages/react/src/ButtonGroup/ButtonGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ const ButtonGroup = React.forwardRef(function ButtonGroup(
{as: BaseComponent = 'div', children, className, role, ...rest},
forwardRef,
) {
const buttons = React.Children.map(children, (child, index) => <div key={index}>{child}</div>)
const buttons = React.Children.map(children, (child, index) => (
<div key={index} className={classes.Item}>
{child}
</div>
))
const buttonRef = useProvidedRefOrCreate(forwardRef as React.RefObject<HTMLDivElement | null>)

useFocusZone({
Expand Down
33 changes: 18 additions & 15 deletions packages/react/src/Checkbox/Checkbox.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,31 @@
/* stylelint-disable-next-line primer/colors */
border-color: var(--control-checked-bgColor-rest);

&::before {
animation: checkmarkIn 80ms cubic-bezier(0.65, 0, 0.35, 1) forwards 80ms;
}

&:disabled {
background-color: var(--control-checked-bgColor-disabled);
border-color: var(--control-checked-borderColor-disabled);
opacity: 1;

&::before {
/* stylelint-disable-next-line primer/colors */
background-color: var(--control-checked-fgColor-disabled);
}
}

/* Windows High Contrast mode */
@media (forced-colors: active) {
background-color: canvastext;
border-color: canvastext;
}
}

&:checked::before,
&:indeterminate::before {
animation: checkmarkIn 80ms cubic-bezier(0.65, 0, 0.35, 1) forwards 80ms;
}

&:checked:disabled,
&:indeterminate:disabled {
background-color: var(--control-checked-bgColor-disabled);
border-color: var(--control-checked-borderColor-disabled);
opacity: 1;
}

&:checked:disabled::before,
&:indeterminate:disabled::before {
/* stylelint-disable-next-line primer/colors */
background-color: var(--control-checked-fgColor-disabled);
}

&:disabled {
cursor: not-allowed;
}
Expand Down
21 changes: 12 additions & 9 deletions packages/react/src/DataTable/Pagination.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,46 @@
}

@media ((max-width: calc(768px - 0.02px))) {
.TablePaginationSteps[data-hidden-viewport-ranges*='narrow'] > *:not(:first-child):not(:last-child) {
/* stylelint-disable-next-line selector-max-specificity -- li type subject keeps the selector bucketable for style-recalc perf (github/github-ui#23654) */
.TablePaginationSteps[data-hidden-viewport-ranges*='narrow'] > li:not(:first-child):not(:last-child) {
display: none;
}

.TablePaginationSteps[data-hidden-viewport-ranges*='narrow'] > *:first-child {
.TablePaginationSteps[data-hidden-viewport-ranges*='narrow'] > li:first-child {
margin-inline-end: 0;
}

.TablePaginationSteps[data-hidden-viewport-ranges*='narrow'] > *:last-child {
.TablePaginationSteps[data-hidden-viewport-ranges*='narrow'] > li:last-child {
margin-inline-start: 0;
}
}

@media ((min-width: 768px)) {
.TablePaginationSteps[data-hidden-viewport-ranges*='regular'] > *:not(:first-child):not(:last-child) {
/* stylelint-disable-next-line selector-max-specificity -- li type subject keeps the selector bucketable for style-recalc perf (github/github-ui#23654) */
.TablePaginationSteps[data-hidden-viewport-ranges*='regular'] > li:not(:first-child):not(:last-child) {
display: none;
}

.TablePaginationSteps[data-hidden-viewport-ranges*='regular'] > *:first-child {
.TablePaginationSteps[data-hidden-viewport-ranges*='regular'] > li:first-child {
margin-inline-end: 0;
}

.TablePaginationSteps[data-hidden-viewport-ranges*='regular'] > *:last-child {
.TablePaginationSteps[data-hidden-viewport-ranges*='regular'] > li:last-child {
margin-inline-start: 0;
}
}

@media ((min-width: 1400px)) {
.TablePaginationSteps[data-hidden-viewport-ranges*='wide'] > *:not(:first-child):not(:last-child) {
/* stylelint-disable-next-line selector-max-specificity -- li type subject keeps the selector bucketable for style-recalc perf (github/github-ui#23654) */
.TablePaginationSteps[data-hidden-viewport-ranges*='wide'] > li:not(:first-child):not(:last-child) {
display: none;
}

.TablePaginationSteps[data-hidden-viewport-ranges*='wide'] > *:first-child {
.TablePaginationSteps[data-hidden-viewport-ranges*='wide'] > li:first-child {
margin-inline-end: 0;
}

.TablePaginationSteps[data-hidden-viewport-ranges*='wide'] > *:last-child {
.TablePaginationSteps[data-hidden-viewport-ranges*='wide'] > li:last-child {
margin-inline-start: 0;
}
}
Expand Down
Loading