Skip to content

Commit

Permalink
fix: nested scroll prevention issue
Browse files Browse the repository at this point in the history
  • Loading branch information
huntabyte committed Nov 9, 2024
1 parent f593851 commit 3a49a24
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions packages/bits-ui/src/lib/internal/use-body-scroll-lock.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,14 @@ export function useBodyScrollLock(
$effect(() => {
return () => {
countState.map.delete(id);

if (!isAnyLocked(countState.map)) {
if (_restoreScrollDelay === null) {
requestAnimationFrame(() => countState.resetBodyStyle());
} else {
afterSleep(_restoreScrollDelay, () => countState.resetBodyStyle());
}
// if any locks are still active, we don't reset the body style
if (isAnyLocked(countState.map)) return;

// if no locks are active (meaning this was the last lock), we reset the body style
if (_restoreScrollDelay === null) {
requestAnimationFrame(() => countState.resetBodyStyle());
} else {
afterSleep(_restoreScrollDelay, () => countState.resetBodyStyle());
}
};
});
Expand Down

0 comments on commit 3a49a24

Please sign in to comment.