diff --git a/packages/bits-ui/src/lib/internal/use-body-scroll-lock.svelte.ts b/packages/bits-ui/src/lib/internal/use-body-scroll-lock.svelte.ts index c27e38b89..c4bffedcc 100644 --- a/packages/bits-ui/src/lib/internal/use-body-scroll-lock.svelte.ts +++ b/packages/bits-ui/src/lib/internal/use-body-scroll-lock.svelte.ts @@ -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()); } }; });