Skip to content

Commit 1f13d5b

Browse files
siddharthkpjoshblack
authored andcommitted
NavList SSR: use useIsomorphicLayoutEffect instead of useLayoutEffect (#3127)
* use useIsomorphicLayoutEffect * Create .changeset/fast-panthers-refuse.md --------- Co-authored-by: Josh Black <joshblack@github.com>
1 parent 5888d44 commit 1f13d5b

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

.changeset/fast-panthers-refuse.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/react": patch
3+
---
4+
5+
Suppress SSR warning for useLayoutEffect in NavList, use useIsomorphicLayoutEffect instead of useLayoutEffect

src/NavList/NavList.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import StyledOcticon from '../StyledOcticon'
1313
import sx, {merge, SxProp} from '../sx'
1414
import {defaultSxProp} from '../utils/defaultSxProp'
1515
import {useId} from '../hooks/useId'
16+
import useIsomorphicLayoutEffect from '../utils/useIsomorphicLayoutEffect'
1617

1718
// ----------------------------------------------------------------------------
1819
// NavList
@@ -110,7 +111,7 @@ function ItemWithSubNav({children, subNav, sx: sxProp = defaultSxProp}: ItemWith
110111
const subNavRef = React.useRef<HTMLDivElement>(null)
111112
const [containsCurrentItem, setContainsCurrentItem] = React.useState(false)
112113

113-
React.useLayoutEffect(() => {
114+
useIsomorphicLayoutEffect(() => {
114115
if (subNavRef.current) {
115116
// Check if SubNav contains current item
116117
const currentItem = subNavRef.current.querySelector('[aria-current]')

0 commit comments

Comments
 (0)