Skip to content
Merged
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
6 changes: 2 additions & 4 deletions packages/react/src/Dialog/Dialog.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,7 +16,6 @@ import type {ForwardRefComponent as PolymorphicForwardRefComponent} from '../uti
import classes from './Dialog.module.css'
import {clsx} from 'clsx'
import {useSlots} from '../hooks/useSlots'
import {useFeatureFlag} from '../FeatureFlags'

/* Dialog Version 2 */

Expand DownExpand Up@@ -290,11 +289,10 @@ const _Dialog = React.forwardRef<HTMLDivElement, React.PropsWithChildren<DialogP
[onClose],
)

const usePerfOptimization = useFeatureFlag('primer_react_css_has_selector_perf')

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)
Expand All@@ -318,7 +316,7 @@ const _Dialog = React.forwardRef<HTMLDivElement, React.PropsWithChildren<DialogP
}
}
}
}, [usePerfOptimization])
}, [])

const header = slots.header ?? (renderHeader ?? DefaultHeader)(defaultedProps)
const body = slots.body ?? (renderBody ?? DefaultBody)({...defaultedProps, children: childrenWithoutSlots})
Expand Down
5 changes: 3 additions & 2 deletions packages/react/src/FeatureFlags/FeatureFlags.tsx
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
import type React from 'react'
import {useContext, useMemo, useEffect} from 'react'
import {useContext, useMemo} from 'react'
import {FeatureFlagContext} from './FeatureFlagContext'
import {FeatureFlagScope, type FeatureFlags} from './FeatureFlagScope'
import useIsomorphicLayoutEffect from '../utils/useIsomorphicLayoutEffect'

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

// Set body attribute for CSS :has() optimization when flag is enabled
useEffect(() => {
useIsomorphicLayoutEffect(() => {
if (isOptimizationEnabled) {
dialogScrollOptimizedCount++
document.body.setAttribute('data-dialog-scroll-optimized', '')
Expand Down
Loading