Skip to content

Commit 30c77d8

Browse files
authored
fix(ui): safe call within useEffect teardown (#11135)
`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.
1 parent 707e85e commit 30c77d8

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

packages/ui/src/elements/Nav/context.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ export const NavProvider: React.FC<{
9696
// when the component unmounts, clear all body scroll locks
9797
useEffect(() => {
9898
return () => {
99-
navRef.current.style.overscrollBehavior = 'auto'
99+
if (navRef.current) {
100+
navRef.current.style.overscrollBehavior = 'auto'
101+
}
100102
}
101103
}, [])
102104

0 commit comments

Comments
 (0)