Skip to content

Commit 36ecba6

Browse files
Copilotmattcosta7
andauthored
Refactor Dialog to check DOM attribute instead of useFeatureFlag hook (#7398)
Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: mattcosta7 <[email protected]>
1 parent eaf4653 commit 36ecba6

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

packages/react/src/Dialog/Dialog.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import type {ForwardRefComponent as PolymorphicForwardRefComponent} from '../uti
1616
import classes from './Dialog.module.css'
1717
import {clsx} from 'clsx'
1818
import {useSlots} from '../hooks/useSlots'
19-
import {useFeatureFlag} from '../FeatureFlags'
2019

2120
/* Dialog Version 2 */
2221

@@ -290,11 +289,10 @@ const _Dialog = React.forwardRef<HTMLDivElement, React.PropsWithChildren<DialogP
290289
[onClose],
291290
)
292291

293-
const usePerfOptimization = useFeatureFlag('primer_react_css_has_selector_perf')
294-
295292
React.useEffect(() => {
296293
const scrollbarWidth = window.innerWidth - document.body.clientWidth
297294
const dialog = dialogRef.current
295+
const usePerfOptimization = document.body.hasAttribute('data-dialog-scroll-optimized')
298296

299297
// Add DisableScroll class to this dialog (for legacy :has() selector path)
300298
dialog?.classList.add(classes.DisableScroll)
@@ -318,7 +316,7 @@ const _Dialog = React.forwardRef<HTMLDivElement, React.PropsWithChildren<DialogP
318316
}
319317
}
320318
}
321-
}, [usePerfOptimization])
319+
}, [])
322320

323321
const header = slots.header ?? (renderHeader ?? DefaultHeader)(defaultedProps)
324322
const body = slots.body ?? (renderBody ?? DefaultBody)({...defaultedProps, children: childrenWithoutSlots})

packages/react/src/FeatureFlags/FeatureFlags.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import type React from 'react'
2-
import {useContext, useMemo, useEffect} from 'react'
2+
import {useContext, useMemo} from 'react'
33
import {FeatureFlagContext} from './FeatureFlagContext'
44
import {FeatureFlagScope, type FeatureFlags} from './FeatureFlagScope'
5+
import useIsomorphicLayoutEffect from '../utils/useIsomorphicLayoutEffect'
56

67
export type FeatureFlagsProps = React.PropsWithChildren<{
78
flags: FeatureFlags
@@ -39,7 +40,7 @@ export function FeatureFlags({children, flags}: FeatureFlagsProps) {
3940
const isOptimizationEnabled = value.enabled('primer_react_css_has_selector_perf')
4041

4142
// Set body attribute for CSS :has() optimization when flag is enabled
42-
useEffect(() => {
43+
useIsomorphicLayoutEffect(() => {
4344
if (isOptimizationEnabled) {
4445
dialogScrollOptimizedCount++
4546
document.body.setAttribute('data-dialog-scroll-optimized', '')

0 commit comments

Comments
 (0)