Skip to content

Commit be5ec9e

Browse files
committed
add data-ssr-hidden attribute
1 parent 61ad00a commit be5ec9e

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

packages/react/src/internal/components/UnderlineTabbedInterface.module.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
/* stylelint-disable-next-line primer/box-shadow */
1313
box-shadow: inset 0 -1px var(--borderColor-muted);
1414

15+
/* Hide overflow during SSR to prevent horizontal scrollbar before JS hydration calculates which items fit */
16+
overflow: hidden;
17+
18+
&[data-ssr-hidden='false'] {
19+
overflow: visible;
20+
}
21+
1522
&[data-variant='flush'] {
1623
/* stylelint-disable-next-line primer/spacing */
1724
padding-inline: unset;

packages/react/src/internal/components/UnderlineTabbedInterface.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
// Used for UnderlineNav and UnderlinePanels components
22

3-
import React from 'react'
3+
import React, {useState} from 'react'
44
import {type ForwardedRef, forwardRef, type FC, type PropsWithChildren, type ElementType} from 'react'
55
import {isElement} from 'react-is'
66
import type {IconProps} from '@primer/octicons-react'
77
import CounterLabel from '../../CounterLabel'
88
import type {ForwardRefComponent as PolymorphicForwardRefComponent} from '../../utils/polymorphic'
9+
import useIsomorphicLayoutEffect from '../../utils/useIsomorphicLayoutEffect'
910

1011
import classes from './UnderlineTabbedInterface.module.css'
1112
import {clsx} from 'clsx'
@@ -22,10 +23,19 @@ type UnderlineWrapperProps<As extends React.ElementType> = {
2223

2324
export const UnderlineWrapper = forwardRef((props, ref) => {
2425
const {children, className, as: Component = 'div', ...rest} = props
26+
// Track hydration state: true on server and initial client render, false after hydration
27+
const [isSSR, setIsSSR] = useState(true)
28+
29+
useIsomorphicLayoutEffect(() => {
30+
// After hydration, allow overflow to be visible
31+
setIsSSR(false)
32+
}, [])
33+
2534
return (
2635
<Component
2736
className={clsx(classes.UnderlineWrapper, className)}
2837
ref={ref as ForwardedRef<HTMLDivElement>}
38+
data-ssr-hidden={isSSR ? 'true' : 'false'}
2939
{...rest}
3040
>
3141
{children}

0 commit comments

Comments
 (0)