Skip to content

fix(core): coordinate concurrent useScrollLock instances - #4788

Merged
cixzhang merged 4 commits into
meta:mainfrom
alex-js-ltd:fix/scroll-lock-out-of-order-cleanup
Aug 13, 2026
Merged

cixzhang merged 4 commits into
meta:mainfrom
alex-js-ltd:fix/scroll-lock-out-of-order-cleanup

Conversation

@alex-js-ltd

Copy link
Copy Markdown
Contributor

Fixes #4787

useScrollLock had no coordination between instances — each call independently snapshotted document.body.style when its own effect mounted and restored that exact snapshot on cleanup. With two overlays open at once (e.g. a Lightbox opened from within a Dialog), closing them out of stacking order could unlock the body while one was still open, and could leave the body permanently stuck locked after both closed.

Changes

  • useScrollLock now coordinates locks with a shared counter: the original body state is captured only when the count goes 0→1, and only restored when it goes back to 0, regardless of which instance closes first.
  • Added regression tests covering a single lock, and two concurrent locks closed both in and out of order.

Test plan

  • pnpm -F @astryxdesign/core test -- useScrollLock — all pass, including the new concurrent-instance tests, which fail against the prior per-instance-snapshot implementation.
  • Full Dialog, Lightbox, Drawer, BottomSheet suites (the hook's real consumers) still pass — no regressions.
  • pnpm check:changesets

@vercel

vercel Bot commented Aug 7, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview Aug 7, 2026 11:46am

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 7, 2026
@github-actions github-actions Bot added the community Authored by a community contributor (not on the eng/design team) label Aug 7, 2026
@github-actions github-actions Bot added needs:code-review High-risk change (new package/component/API) — needs human code review before merge needs:design-review Affects visuals — Design should review labels Aug 7, 2026
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

No new or modified components detected.

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.7KB 1.2KB

Accessibility Audit

Status: No accessibility violations detected.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

github-actions Bot added a commit that referenced this pull request Aug 7, 2026

@cixzhang cixzhang 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.

Thanks this seems good for nested dialogs

@cixzhang
cixzhang enabled auto-merge (squash) August 13, 2026 04:40
@github-actions github-actions Bot removed the needs:code-review High-risk change (new package/component/API) — needs human code review before merge label Aug 13, 2026
@cixzhang
cixzhang merged commit 757185e into meta:main Aug 13, 2026
22 checks passed
@github-actions
github-actions Bot deleted the fix/scroll-lock-out-of-order-cleanup branch August 13, 2026 07:08

This branch was successfully deployed

1 active deployment
Preview — 3f249735 Deployed Aug 7, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. community Authored by a community contributor (not on the eng/design team) needs:design-review Affects visuals — Design should review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

useScrollLock: concurrent overlays corrupt body scroll state when closed out of order

3 participants