Skip to content

Commit

Permalink
fix(ui): safe call within useEffect teardown (#11135)
Browse files Browse the repository at this point in the history
`NavProvider` useEffects teardown is trying to set `style` on an element
that may not exist. The original code produces the following error:


![image](https://github.com/user-attachments/assets/11a83fbe-67eb-42a9-bd78-749ea98b67c5)

![image](https://github.com/user-attachments/assets/28ed2534-2387-416b-8191-d68b478161aa)

Therefore, a condition has been added to check if `navRef.current` is
truthy.
  • Loading branch information
GeorgeHulpoi authored and kendelljoseph committed Feb 21, 2025
1 parent 7dc66e5 commit a46ded3
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/ui/src/elements/Nav/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ export const NavProvider: React.FC<{
// when the component unmounts, clear all body scroll locks
useEffect(() => {
return () => {
navRef.current.style.overscrollBehavior = 'auto'
if (navRef.current) {
navRef.current.style.overscrollBehavior = 'auto'
}
}
}, [])

Expand Down

0 comments on commit a46ded3

Please sign in to comment.