You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
useScrollLock: concurrent overlays corrupt body scroll state when closed out of order #4787
useScrollLock (packages/core/src/hooks/useScrollLock.ts) has no coordination between instances — each call independently snapshots document.body.style when its own effect mounts and restores that exact snapshot on cleanup. I confirmed this directly against the hook (two concurrent renderHook(() => useScrollLock(true)) calls, unmounted out of order — see regression tests below).
The same hook is called, unmodified, by Dialog, Lightbox, and by Drawer/BottomSheet in packages/lab — since none of them wrap or alter the hook's behavior, the same bug applies to any pairing of these opened concurrently (e.g. a Lightbox opened from within a Dialog).
Failure sequence with two overlays open at once:
Overlay A opens, saves the true original body style, locks the body.
Overlay B opens on top, saves A's already-locked style as its "original."
A closes first (B still open) → A restores the true original → body unlocks while B is still open.
B closes → B restores what it saved in step 2 (hidden/fixed) → body is now stuck locked permanently, with nothing left open to undo it.
Regression tests (fail against main):
it('stays locked while a second overlay is still open, even if the first closes out of order',()=>{vi.spyOn(window,'scrollTo').mockImplementation(()=>{});constfirst=renderHook(()=>useScrollLock(true));constsecond=renderHook(()=>useScrollLock(true));first.unmount();expect(document.body.style.position).toBe('fixed');expect(document.body.style.overflow).toBe('hidden');second.unmount();});it('fully restores the body once every overlay has closed, regardless of close order',()=>{vi.spyOn(window,'scrollTo').mockImplementation(()=>{});constfirst=renderHook(()=>useScrollLock(true));constsecond=renderHook(()=>useScrollLock(true));first.unmount();second.unmount();expect(document.body.style.position).toBe('');expect(document.body.style.overflow).toBe('');expect(document.body.style.top).toBe('');expect(document.body.style.left).toBe('');expect(document.body.style.right).toBe('');});
I've opened #4788 with regression tests and a proposed fix.
Activity