Skip to content

[dialog] Fix scroll lock handoff with external overlays - #4665

Merged
atomiks merged 1 commit into
mui:masterfrom
atomiks:codex/scroll-lock-handoff
Jul 19, 2026
Merged

atomiks merged 1 commit into
mui:masterfrom
atomiks:codex/scroll-lock-handoff

Conversation

@atomiks

@atomiks atomiks commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

Fixes #4640

Base UI was treating an externally scroll-locked page as settled state, which breaks delayed handoffs from non-Base-UI overlays. If a third-party overlay clears its html or body lock after Dialog opens, the page can become scrollable under the open popup or stay locked after close.

Changes

  • Wait for external html or body scroll locks to clear before Base UI takes over its own lock.
  • Add a regression test that covers both body and html handoffs into Dialog.

@atomiks atomiks added type: bug It doesn't behave as expected. component: dialog Changes related to the dialog component. labels Apr 22, 2026 — with ChatGPT Codex Connector
@pkg-pr-new

pkg-pr-new Bot commented Apr 22, 2026 •

Copy link
Copy Markdown
  • base-ui-tanstack-start

  • vite-css-base-ui-example

    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/react@4665
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@4665
    

commit: 4668ab1

@code-infra-dashboard

code-infra-dashboard Bot commented Apr 22, 2026 •

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+259B(+0.06%) 🔺+58B(+0.04%)

Details of bundle changes

Performance

Total duration: 1,233.32 ms -17.19 ms(-1.4%) | Renders: 78 (+0) | Paint: 1,952.26 ms -34.16 ms(-1.7%)

Test Duration Renders
Combobox type — 500 items, narrows to ~11 (type "Row 25") 36.13 ms ▼-11.63 ms(-24.4%) 15 (+0)
Combobox type — 500 items, all stay mounted (type "Row ") 29.72 ms ▼-10.59 ms(-26.3%) 11 (+0)

13 tests within noise — details


Check out the code infra dashboard for more information about this PR.

@netlify

netlify Bot commented Apr 22, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 4668ab1
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a5d5d2bea4b6e000888a620
😎 Deploy Preview https://deploy-preview-4665--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@atomiks
atomiks force-pushed the codex/scroll-lock-handoff branch from 25fd8b9 to df56ec1 Compare April 22, 2026 14:26
@atomiks
atomiks marked this pull request as ready for review June 10, 2026 07:13
Comment thread packages/utils/src/useScrollLock.ts Resolved
Comment thread packages/utils/src/useScrollLock.ts Outdated
Comment on lines +297 to +298
if (isPageScrollLocked(win, html, body)) {
this.restore = this.observePageScrollUnlock(referenceElement);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So IIUC, we're handling the case where scroll-lock is applied by someone else before we run. Do we also need to handle the case where someone tries to apply a scroll-lock after we have already applied a scroll-lock?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, and the inverse is harder. Before we lock, we can safely detect an existing external lock and wait, but after Base UI has locked, later locks write to the same html/body style/clase attr, so there isn’t a reliable signal to tell which overflow: hidden belongs to which lib

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've thought about this a bit more, and I think we should avoid including too much complexity in our codebase to deal with this issue. We should aim/optimize for the case where we're the sole low-level library and not try to fix every edge-case with users mix and matching libraries. We're adding complexity & bundle-size costs for everyone by doing so.

I think dealing with this edge-case is fine, but if there are more we should expose the ScrollLocker and let users integrate libraries cleanly instead of us trying to guess what happens by observing the DOM.

Comment thread packages/utils/src/useScrollLock.ts Resolved

@romgrk romgrk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM beyond the missing comment. Maybe the names could be reworked to hasExternalScrollLock and observeExternalScrollUnlock — "external" makes it more clear what those are for, and "page" doesn't add much as the scroll lock always apply to the full page.

@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jun 24, 2026
@oliviertassinari
oliviertassinari requested a review from jjenzz as a code owner June 27, 2026 20:50
@ciampo

ciampo commented Jul 16, 2026

Copy link
Copy Markdown

Hey @atomiks , do you plan on resuming work on this anytime soon? If not, can I help to push this PR to the finish line?

@atomiks
atomiks force-pushed the codex/scroll-lock-handoff branch from 4314152 to 3e7a58a Compare July 19, 2026 22:04
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jul 19, 2026
@atomiks
atomiks force-pushed the codex/scroll-lock-handoff branch 2 times, most recently from a966837 to 2e8fc77 Compare July 19, 2026 22:28
@atomiks
atomiks force-pushed the codex/scroll-lock-handoff branch from 2e8fc77 to 4668ab1 Compare July 19, 2026 23:26
@atomiks
atomiks merged commit 3dceede into mui:master Jul 19, 2026
6 checks passed
mikemai2awesome added a commit to mikemai2awesome/base-ui-a11y that referenced this pull request Jul 24, 2026
…es (#3)

* [popups] Fix scroll lock handoff with external overlays (mui#4665)

(cherry picked from commit 3dceede)

* fix double backdrop

* catch up with upstream dialog
@atomiks
atomiks deleted the codex/scroll-lock-handoff branch August 11, 2026 03:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: dialog Changes related to the dialog component. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[dialog] scroll locking mechanism doesn't handoff well with non-base ui modal overlays

3 participants