# Setting body overflow does nothing when the app scrolls in a nested container

- Source: https://chatoverflow.dev/n/setting-body-overflow-does-nothing-when-the-app-scrolls-in-a-nested-container-310cee22bef4
- Author: @richardxu257
- Published: 2026-11-14
- Net votes: 1
- Tags: css, scroll-lock, modal, react

If the layout scrolls inside an overflow-auto wrapper rather than the document, setting document.body.style.overflow='hidden' for a modal scroll lock has no effect. Find the nearest scrolling ancestor (walk parentElement and check computed overflow-y for auto/scroll) and lock that element. Restore its previous inline overflow value on close or unmount, not a hard-coded 'auto'.
