-
Notifications
You must be signed in to change notification settings - Fork 655
Graduate primer_react_css_has_selector_perf feature flag
#7633
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
9daa85c
e13237f
e0b2542
94a5e2f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@primer/react': patch | ||
| --- | ||
|
|
||
| Graduate `primer_react_css_has_selector_perf` feature flag: the CSS `:has()` performance optimization (`body[data-dialog-scroll-disabled]`) is now the default behavior for Dialog scroll disabling |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,13 @@ import {useSlots} from '../hooks/useSlots' | |
|
|
||
| /* Dialog Version 2 */ | ||
|
|
||
| /** | ||
| * Ref count for data-dialog-scroll-disabled attribute management. | ||
| * Tracks how many dialogs are currently open to know when to remove the attribute. | ||
| * This is client-only: it is only accessed inside useEffect, which never runs on the server. | ||
| */ | ||
| let dialogScrollDisabledCount = 0 | ||
|
|
||
| /** | ||
| * Props that characterize a button to be rendered into the footer of | ||
| * a Dialog. | ||
|
|
@@ -267,7 +274,6 @@ const _Dialog = React.forwardRef<HTMLDivElement, React.PropsWithChildren<DialogP | |
| const autoFocusedFooterButtonRef = useRef<HTMLButtonElement>(null) | ||
| for (const footerButton of footerButtons) { | ||
| if (footerButton.autoFocus) { | ||
| // eslint-disable-next-line react-hooks/immutability | ||
| footerButton.ref = autoFocusedFooterButtonRef | ||
| } | ||
| } | ||
|
|
@@ -308,29 +314,16 @@ const _Dialog = React.forwardRef<HTMLDivElement, React.PropsWithChildren<DialogP | |
|
|
||
| React.useEffect(() => { | ||
| const scrollbarWidth = window.innerWidth - document.body.clientWidth | ||
| const dialog = dialogRef.current | ||
| const usePerfOptimization = document.body.hasAttribute('data-dialog-scroll-optimized') | ||
|
|
||
| // Add DisableScroll class to this dialog (for legacy :has() selector path) | ||
| dialog?.classList.add(classes.DisableScroll) | ||
| dialogScrollDisabledCount++ | ||
| document.body.style.setProperty('--prc-dialog-scrollgutter', `${scrollbarWidth}px`) | ||
|
|
||
| if (usePerfOptimization) { | ||
| // Optimized path: set attribute on body for direct CSS targeting | ||
| document.body.setAttribute('data-dialog-scroll-disabled', '') | ||
| } | ||
| // Legacy path: no action needed - CSS :has(.Dialog.DisableScroll) handles it | ||
| document.body.setAttribute('data-dialog-scroll-disabled', '') | ||
|
|
||
|
Comment on lines
315
to
321
|
||
| return () => { | ||
| dialog?.classList.remove(classes.DisableScroll) | ||
|
|
||
| const remainingDialogs = document.querySelectorAll(`.${classes.DisableScroll}`) | ||
|
|
||
| if (remainingDialogs.length === 0) { | ||
| dialogScrollDisabledCount-- | ||
| if (dialogScrollDisabledCount === 0) { | ||
| document.body.style.removeProperty('--prc-dialog-scrollgutter') | ||
| if (usePerfOptimization) { | ||
| document.body.removeAttribute('data-dialog-scroll-disabled') | ||
| } | ||
| document.body.removeAttribute('data-dialog-scroll-disabled') | ||
| } | ||
| } | ||
| }, []) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
footerButtonsloop still mutatesfooterButton.ref, but theeslint-disable-next-line react-hooks/immutabilitywas removed. If the repo’s immutability lint rule still applies here (it’s used elsewhere), this will fail linting. Either restore the targeted eslint-disable for this assignment or refactor to avoid mutating thefooterButtonsobjects (e.g., derive a new array/object for rendering).