Skip to content

fix(scraps): Make modal scroll locking hold up on mobile - #132288

Draft
sentry-junior[bot] wants to merge 1 commit into
masterfrom
fix/mobile-modal-scroll-lock
Draft

sentry-junior[bot] wants to merge 1 commit into
masterfrom
fix/mobile-modal-scroll-lock

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

This fixes the shared scroll lock and modal host behind the "broken or janky modals on mobile" reports. It's the follow-up to #132285, which fixes modals with no height on Safari and iOS before 18.4. The two PRs are independent.

useScrollLock

  • One lock per container. When an idle hook unmounted, its cleanup deleted the container's Lock from the map. Hooks that stay mounted (GlobalModal, GlobalDrawer) kept the old instance, and the next hook to mount (MobileNavigation, ReorderableList) created a second one. Both saved and restored body styles on their own. Opening a modal over the mobile nav and then closing both unlocked the page while the modal was open, and left body stuck on position: fixed afterwards. Locks now stay in a WeakMap.
  • Scroll restores in the same task. While the body is fixed, scrollY is 0. With the requestAnimationFrame restore, an acquire right after a release (one modal replacing another, or a drawer closing as a modal opens) read that 0, pinned the page at the top, and lost the position on close. scrollTo forces layout with the restored styles, so it works synchronously.
  • Scrollbar width from layout. The scrollbar width is now the documentElement.clientWidth gained by pinning the body. innerWidth follows the pinch-zoomed visual viewport on iOS, so the old formula could produce negative or very large padding and --scrollbar-size.

Modal host

  • Lock effect runs on open and close only. Locking, background hiding and focus return no longer depend on per-modal values. A replacement modal keeps the lock, and focus goes back to what opened the first modal instead of an element that no longer exists. The focus trap still re-activates for each modal.
  • Scroll container tracks visualViewport. It uses offsetTop and height. The on-screen keyboard and pinch zoom only shrink the visual viewport, which could leave the footer (Confirm, Delete) under the keyboard while the body was pinned. The container also gets overscroll-behavior: contain.
  • Keyboard closes first. openModal blurs a focused text field before the page locks. This is what fix(onboarding): Keep the framework prompt usable on mobile #132109 does for one prompt, applied to every modal.
  • Focus return doesn't scroll. Focus goes back with preventScroll.

Other

  • Drawer: a passive drawer that replaces a locking drawer now releases the lock.
  • Framework suggestion modal: 80vh becomes 80dvh, and the 550px and 631px minimum heights are capped at 80dvh, so the dialog fits a phone with its toolbars showing.

Everything used is within our browserslist floor (iOS 18.0, Safari 17.0): dvh (Safari 15.4), overscroll-behavior (16), visualViewport (13).

Open before review: the visual-viewport sizing and the keyboard handling need a real iOS and Android device. Chromium emulation doesn't reproduce how WebKit handles the keyboard. Use the framework suggestion modal story from #132201 with and without the keyboard open, plus a modal with an input near its footer.

Refs #132108

via @natemoo-re.

--

View Session [Sentry]

useScrollLock could create a second Lock for document.body after an idle hook unmounted, so the mobile nav and the modal saved and restored body styles independently. The page could unlock under an open modal or stay fixed after everything closed. Locks now live for the page, scroll restores in the same task, and the scrollbar width comes from layout widths instead of innerWidth, which tracks pinch zoom on iOS.

The modal host now locks, hides the background, and restores focus only when it opens or closes, so a modal that replaces another keeps the page position. Its scroll container follows the visual viewport so the on-screen keyboard does not cover the footer, and openModal blurs a focused text field first. A passive drawer that replaces a locking drawer now unlocks the page, and the framework suggestion modal caps its heights to the dynamic viewport.

Refs #132108

Co-Authored-By: nate <7118177+natemoo-re@users.noreply.github.com>
@github-actions github-actions Bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Nov 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Story previews

Preview the stories changed in this PR on the Vercel deployment:

Preview deployment: https://sentry-igdfd0bf1.sentry.dev

This branch was successfully deployed

1 active deployment
Preview — 09a1cc8f Deployed Nov 23, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant