Skip to content

Commit 41354f6

Browse files
authored
fix: cleanup bodyscroll locks if bottomsheet is force unmounted (#2460)
* fix: cleanup bodyscroll locks if bottomsheet is force unmounted * Create chatty-dolphins-care.md
1 parent 94cf1d2 commit 41354f6

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

.changeset/chatty-dolphins-care.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@razorpay/blade": patch
3+
---
4+
5+
fix(blade): cleanup bodyscroll locks if bottomsheet is force unmounted

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

+17-1
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)