v6.5.3
π Bug Fixes
useScrollLock: releases the lock when the owning component unmounts
The lock is an inline overflow: hidden written onto an element the hook doesn't own β usually document.body β plus, on iOS, a touchmove guard registered with passive: false. Neither was ever cleaned up: the effect that applies the style had no teardown, and the listener was only detached from unlock().
So unmounting while locked leaked both. The usual way in is a route change with the modal still open:
function Modal({ open }: { open: boolean }) {
const [, setLocked] = useScrollLock(() => document.body);
useEffect(() => { setLocked(open); }, [open, setLocked]);
// navigate away while open β the component goes, the lock stays
}The page is left permanently unscrollable, with nothing mounted that could release it. On iOS it is worse than a stray style: the leftover passive: false listener stays attached to the element and cancels every touch scroll for the rest of the session.
useUnmount now restores the exact inline overflow captured before locking, and detaches the guard:
| unmounting while⦠| before | after |
|---|---|---|
| locked β the style | overflow: hidden stays |
original inline value restored |
locked β the iOS touchmove guard |
listener stays on the element | listener removed |
| unlocked | untouched | untouched |
This is the behaviour the docs already promised β "the lock is automatically released when the component unmounts" β the implementation just never did it.
Pairing every lock with an unlock is still the right pattern, because unmounting is only half of it. The modal closing while the component stays mounted is yours either way:
useEffect(() => {
setLocked(open);
return () => setLocked(false);
}, [open, setLocked]);useScrollLock also picks up its first test suite (6 cases): the lock/unlock round-trip, release on unmount, no-op on an unlocked unmount, iOS listener teardown, initialState, and getter / null targets.
π Deep dive, including why overflow: hidden alone never stopped iOS rubber-banding: React useScrollLock Hook: Lock Body Scroll for Modals
Full Changelog: v6.5.2...v6.5.3