Skip to content

Commit cd0b66a

Browse files
committed
fix: cleanup bodyscroll locks if bottomsheet is force unmounted
1 parent db5c906 commit cd0b66a

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

packages/blade/src/components/BottomSheet/BottomSheet.web.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import React from 'react';
66
import styled from 'styled-components';
77
import { rubberbandIfOutOfBounds, useDrag } from '@use-gesture/react';
88
import usePresence from 'use-presence';
9-
import { clearAllBodyScrollLocks } from 'body-scroll-lock-upgrade';
9+
import { clearAllBodyScrollLocks, enableBodyScroll } from 'body-scroll-lock-upgrade';
1010
import { BottomSheetHeader } from './BottomSheetHeader';
1111
import { BottomSheetFooter } from './BottomSheetFooter';
1212
import { BottomSheetBody } from './BottomSheetBody';
@@ -433,6 +433,22 @@ const _BottomSheet = ({
433433
}
434434
}, [addBottomSheetToStack, id, isMounted, removeBottomSheetFromStack]);
435435

436+
// Remove the bottomsheet from the stack, if it's unmounted forcefully
437+
React.useEffect(() => {
438+
return () => {
439+
if (id === undefined) return;
440+
removeBottomSheetFromStack(id);
441+
};
442+
}, [id, removeBottomSheetFromStack]);
443+
444+
// Disable body scroll lock when the component is unmounted forcefully
445+
React.useEffect(() => {
446+
const lockTarget = scrollRef.current!;
447+
return () => {
448+
enableBodyScroll(lockTarget);
449+
};
450+
}, []);
451+
436452
// We will need to reset these values otherwise the next time the bottomsheet opens
437453
// this will be populated and the animations won't run
438454
// why?: because how the usePresence hook works, we actually just unmount the

0 commit comments

Comments
 (0)