An open source design system that's fully customizable and agent ready
TypeScript
fix: reserve the scrollbar's width while scroll is locked (#5219)
Xinzi Zhou8eaa92a7e866
diff --git a/.changeset/scroll-lock-scrollbar-gutter.md b/.changeset/scroll-lock-scrollbar-gutter.mdnew file mode 100644index 0000000000..a11bf97b4e--- /dev/null+++ b/.changeset/scroll-lock-scrollbar-gutter.md@@ -0,0 +1,19 @@+---+'@astryxdesign/core': patch+---++[fix] Opening a Dialog, BottomSheet, Lightbox, or MobileNav no longer shifts the page sideways when the browser has a classic scrollbar++@imdreamrunner++Locking background scroll hides the document's scrollbar. Where that scrollbar+takes layout space — Windows/Linux desktop, and macOS set to always show scroll+bars — hiding it widened the layout viewport by its width (~15px), so the whole+page reflowed sideways behind the overlay and back again on close.++Both scroll locks now hold that gutter open with `scrollbar-gutter: stable` for+the duration of the lock, which keeps `position: fixed` chrome (sticky headers,+toast viewports) still as well as in-flow content. Pages with no space-taking+scrollbar, and pages that already set `scrollbar-gutter` themselves, are left+alone. Engines without `scrollbar-gutter` support fall back to padding the+measured difference.diff --git a/packages/core/src/MobileNav/MobileNav.tsx b/packages/core/src/MobileNav/MobileNav.tsxindex 258ba0978f..0714f3f13a 100644--- a/packages/core/src/MobileNav/MobileNav.tsx+++ b/packages/core/src/MobileNav/MobileNav.tsx@@ -23,6 +23,7 @@** SYNC: When modified, update these files to stay in sync:* - /packages/core/src/MobileNav/index.ts (exports if types change)+ * - /packages/core/src/hooks/scrollbarGutter.ts (shared scroll-lock gutter)* - /packages/cli/assets/templates/blocks/components/MobileNav/ (showcase blocks)*/@@ -47,6 +48,10 @@ import {Button} from '../Button';import {Icon} from '../Icon';import {Heading} from '../Heading/Heading';import {useAppShellMobile} from '../AppShell/AppShellMobileContext';+import {+ holdScrollbarGutter,+ type ScrollbarGutterHold,+} from '../hooks/scrollbarGutter';import {mergeProps, mergeRefs, composeEventHandlers} from '../utils';import type {BaseProps} from '../BaseProps';import {themeProps} from '../utils/themeProps';@@ -433,6 +438,15 @@ export function MobileNav({const dialogRef = useRef<HTMLDialogElement>(null);const closeTimeoutRef = useRef<ReturnType<typeof setTimeout>>(null);+ const gutterRef = useRef<ScrollbarGutterHold | null>(null);++ // Gives back the gutter held open in place of the hidden scrollbar.+ const releaseGutter = useCallback(() => {+ if (gutterRef.current) {+ gutterRef.current.release();+ gutterRef.current = null;+ }+ }, []);// Resolved side — computed from trigger position when side='auto'const [resolvedSide, setResolvedSide] = useState<'start' | 'end'>(side === 'auto' ? 'end' : side,@@ -475,6 +489,10 @@ export function MobileNav({}if (isOpen) {+ // Taken first: every mutation below is one that can hide the scrollbar,+ // and the gutter has to be measured while it is still there.+ gutterRef.current ??= holdScrollbarGutter(document.documentElement);+if (!dialog.open) {dialog.showModal();}@@ -482,8 +500,10 @@ export function MobileNav({// overflow: clip avoids creating a scroll container (unlike hidden),// so there's no scroll bounce and no need to save/restore scroll position.document.documentElement.style.overflow = 'clip';+ gutterRef.current.settle();} else if (dialog.open) {document.documentElement.style.overflow = '';+ releaseGutter();closeTimeoutRef.current = setTimeout(() => {dialog.close();@@ -496,8 +516,9 @@ export function MobileNav({closeTimeoutRef.current = null;}document.documentElement.style.overflow = '';+ releaseGutter();};- }, [isOpen]);+ }, [isOpen, releaseGutter]);// Close the native dialog on unmount if it's still open. Inside AppShell the// drawer is mounted in an <Activity> that switches to mode="hidden" when thediff --git a/packages/core/src/MobileNav/MobileNavScrollbarGutter.test.tsx b/packages/core/src/MobileNav/MobileNavScrollbarGutter.test.tsxnew file mode 100644index 0000000000..4572fee186--- /dev/null+++ b/packages/core/src/MobileNav/MobileNavScrollbarGutter.test.tsx@@ -0,0 +1,109 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file MobileNavScrollbarGutter.test.tsx+ * @input Uses vitest, @testing-library/react, MobileNav, a stubbed viewport+ * @output Unit tests for the scrollbar gutter MobileNav reserves while open+ * @position Testing; guards MobileNav.tsx against the open-drawer page shift+ *+ * MobileNav clips the document to lock background scroll, which hides a+ * classic scrollbar and widens the layout viewport by its width — the page+ * behind the drawer jumps sideways. The clip has to be paired with holding+ * that gutter open.+ *+ * SYNC: When MobileNav.tsx changes, update tests to match new behavior+ */++import {describe, it, expect, beforeAll, afterEach} from 'vitest';+import {render, cleanup} from '@testing-library/react';+import {MobileNav} from './MobileNav';++beforeAll(() => {+ // jsdom doesn't implement showModal/close on <dialog>+ HTMLDialogElement.prototype.showModal =+ HTMLDialogElement.prototype.showModal ||+ function (this: HTMLDialogElement) {+ this.setAttribute('open', '');+ };+ HTMLDialogElement.prototype.close =+ HTMLDialogElement.prototype.close ||+ function (this: HTMLDialogElement) {+ this.removeAttribute('open');+ };+});++/** jsdom does no layout, so both halves of the measurement are stubbed. */+function stubViewport(innerWidth: number, clientWidth: number) {+ Object.defineProperty(window, 'innerWidth', {+ value: innerWidth,+ configurable: true,+ writable: true,+ });+ Object.defineProperty(document.documentElement, 'clientWidth', {+ value: clientWidth,+ configurable: true,+ });+}++const rootGutter = () => document.documentElement.style.scrollbarGutter;++describe('MobileNav scrollbar gutter', () => {+ afterEach(() => {+ cleanup();+ document.documentElement.style.cssText = '';+ // @ts-expect-error -- drop the viewport stub so jsdom's own value comes back+ delete document.documentElement.clientWidth;+ });++ it('holds the gutter open while the drawer is open', () => {+ stubViewport(1024, 1009);++ const view = render(+ <MobileNav isOpen={true} onOpenChange={() => {}}>+ <span>Nav content</span>+ </MobileNav>,+ );++ expect(document.documentElement.style.overflow).toBe('clip');+ expect(rootGutter()).toBe('stable');++ view.unmount();++ expect(document.documentElement.style.overflow).toBe('');+ expect(rootGutter()).toBe('');+ });++ it('gives the gutter back when the drawer closes', () => {+ stubViewport(1024, 1009);++ const view = render(+ <MobileNav isOpen={true} onOpenChange={() => {}}>+ <span>Nav content</span>+ </MobileNav>,+ );++ expect(rootGutter()).toBe('stable');++ view.rerender(+ <MobileNav isOpen={false} onOpenChange={() => {}}>+ <span>Nav content</span>+ </MobileNav>,+ );++ expect(rootGutter()).toBe('');+ });++ it('holds nothing when the scrollbar is an overlay one', () => {+ stubViewport(1024, 1024);++ render(+ <MobileNav isOpen={true} onOpenChange={() => {}}>+ <span>Nav content</span>+ </MobileNav>,+ );++ expect(document.documentElement.style.overflow).toBe('clip');+ expect(rootGutter()).toBe('');+ expect(document.documentElement.style.paddingRight).toBe('');+ });+});diff --git a/packages/core/src/hooks/scrollbarGutter.test.ts b/packages/core/src/hooks/scrollbarGutter.test.tsnew file mode 100644index 0000000000..87dcf4ced3--- /dev/null+++ b/packages/core/src/hooks/scrollbarGutter.test.ts@@ -0,0 +1,167 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file scrollbarGutter.test.ts+ * @input Uses vitest and a stubbed viewport + element box (jsdom does no layout)+ * @output Unit tests for holdScrollbarGutter+ * @position Testing; validates scrollbarGutter.ts implementation+ *+ * SYNC: When scrollbarGutter.ts changes, update tests to match new behavior+ */++import {afterEach, describe, expect, it} from 'vitest';+import {holdScrollbarGutter} from './scrollbarGutter';++/**+ * jsdom does no layout, so both halves of the measurement are stubbed: the+ * viewport (`innerWidth` vs `documentElement.clientWidth`) and the element's+ * own box, which `widths` reads from and a test flips to simulate the lock+ * widening it.+ */+function stub({+ innerWidth,+ clientWidth,+ widths,+}: {+ innerWidth: number;+ clientWidth: number;+ widths?: () => number;+}) {+ Object.defineProperty(window, 'innerWidth', {+ value: innerWidth,+ configurable: true,+ writable: true,+ });+ Object.defineProperty(document.documentElement, 'clientWidth', {+ value: clientWidth,+ configurable: true,+ });+ if (widths) {+ document.body.getBoundingClientRect = () => ({width: widths()}) as DOMRect;+ }+}++const rootGutter = () => document.documentElement.style.scrollbarGutter;++describe('holdScrollbarGutter', () => {+ afterEach(() => {+ document.body.style.cssText = '';+ document.documentElement.style.cssText = '';+ // @ts-expect-error -- drop the stubs so jsdom's own values come back+ delete document.documentElement.clientWidth;+ // @ts-expect-error -- restore the prototype's implementation+ delete document.body.getBoundingClientRect;+ });++ it('holds the gutter open when a space-taking scrollbar is about to be hidden', () => {+ // A 1024px window over a 1009px layout viewport = a 15px classic scrollbar.+ stub({innerWidth: 1024, clientWidth: 1009});++ const hold = holdScrollbarGutter(document.body);++ expect(rootGutter()).toBe('stable');++ hold.settle();+ hold.release();++ expect(rootGutter()).toBe('');+ });++ it('leaves an overlay scrollbar alone — there is no gutter to hold', () => {+ stub({innerWidth: 1024, clientWidth: 1024});++ const hold = holdScrollbarGutter(document.body);+ hold.settle();++ expect(rootGutter()).toBe('');+ expect(document.body.style.paddingRight).toBe('');++ hold.release();+ });++ it('does not pad when holding the gutter kept the element still', () => {+ stub({innerWidth: 1024, clientWidth: 1009, widths: () => 1009});++ const hold = holdScrollbarGutter(document.body);+ hold.settle();++ expect(rootGutter()).toBe('stable');+ expect(document.body.style.paddingRight).toBe('');++ hold.release();+ });++ it('falls back to padding when the element grew anyway', () => {+ // What an engine without scrollbar-gutter support does: the gutter request+ // is ignored, the scrollbar goes away, and the element widens by 15px.+ let width = 1009;+ stub({innerWidth: 1024, clientWidth: 1009, widths: () => width});++ const hold = holdScrollbarGutter(document.body);+ width = 1024;+ hold.settle();++ expect(document.body.style.paddingRight).toBe('15px');++ hold.release();++ expect(document.body.style.paddingRight).toBe('');+ });++ it("adds to the page's own padding instead of replacing it", () => {+ let width = 1009;+ stub({innerWidth: 1024, clientWidth: 1009, widths: () => width});+ document.body.style.paddingRight = '24px';++ const hold = holdScrollbarGutter(document.body);+ width = 1024;+ hold.settle();++ expect(document.body.style.paddingRight).toBe('39px');++ hold.release();++ expect(document.body.style.paddingRight).toBe('24px');+ });++ it('restores the page\u2019s own scrollbar-gutter rather than clearing it', () => {+ stub({innerWidth: 1024, clientWidth: 1009});+ document.documentElement.style.scrollbarGutter = 'stable both-edges';++ const hold = holdScrollbarGutter(document.body);++ expect(rootGutter()).toBe('stable');++ hold.settle();+ hold.release();++ expect(rootGutter()).toBe('stable both-edges');+ });++ it('settles once, however many times it is called', () => {+ let width = 1009;+ stub({innerWidth: 1024, clientWidth: 1009, widths: () => width});++ const hold = holdScrollbarGutter(document.body);+ width = 1024;+ hold.settle();+ hold.settle();+ hold.settle();++ expect(document.body.style.paddingRight).toBe('15px');++ hold.release();+ });++ it('does nothing where there is no layout to measure', () => {+ stub({innerWidth: 1024, clientWidth: 0});++ const hold = holdScrollbarGutter(document.body);+ hold.settle();++ expect(rootGutter()).toBe('');+ expect(document.body.style.paddingRight).toBe('');++ hold.release();+ });+});diff --git a/packages/core/src/hooks/scrollbarGutter.ts b/packages/core/src/hooks/scrollbarGutter.tsnew file mode 100644index 0000000000..34b0446be6--- /dev/null+++ b/packages/core/src/hooks/scrollbarGutter.ts@@ -0,0 +1,121 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file scrollbarGutter.ts+ * @input The element a scroll lock pins, plus live layout measurements+ * @output Exports holdScrollbarGutter and the ScrollbarGutterHold it returns+ * @position Internal hook utility; used by useScrollLock and MobileNav so that+ * locking background scroll does not resize the layout viewport.+ *+ * Locking scroll hides the document's scrollbar. Where that scrollbar is a+ * classic (space-taking) one — Windows/Linux desktop, and macOS set to+ * "Always" show scroll bars — hiding it widens the layout viewport by the+ * scrollbar's width and the whole page jumps sideways behind the overlay.+ *+ * The fix is `scrollbar-gutter: stable`, which holds the gutter open once the+ * scrollbar goes away. Being a real layout change it holds `position: fixed`+ * chrome (sticky headers, toast viewports) as well as in-flow content, which+ * padding fundamentally cannot: fixed elements resolve against the viewport,+ * not against the padded element.+ *+ * Padding is kept only as a fallback for engines without `scrollbar-gutter`+ * (Safari shipped it in 18.2), and it is applied by measuring whether the+ * element actually moved rather than by assuming it did.+ */++const NOOP: ScrollbarGutterHold = {+ settle() {},+ release() {},+};++export interface ScrollbarGutterHold {+ /**+ * Call once the lock's own styles are applied: measures whether the element+ * grew anyway and, only then, pads the difference away.+ */+ settle(): void;+ /** Call on unlock: restores everything this hold changed. */+ release(): void;+}++/**+ * Keeps `element`'s content box the width it is right now, across a scroll+ * lock that is about to hide the document's scrollbar.+ *+ * Call it *before* applying the lock's styles, then {@link+ * ScrollbarGutterHold.settle} immediately after, and {@link+ * ScrollbarGutterHold.release} on unlock:+ *+ * ```+ * const hold = holdScrollbarGutter(document.body);+ * body.style.position = 'fixed';+ * hold.settle();+ * ```+ *+ * Overlay scrollbars (mobile, default macOS) take no layout space, so there is+ * nothing to hold and nothing is touched.+ */+export function holdScrollbarGutter(element: HTMLElement): ScrollbarGutterHold {+ if (typeof window === 'undefined' || typeof document === 'undefined') {+ return NOOP;+ }++ const root = document.documentElement;+ const viewportWidth = root.clientWidth;++ // 0 means "no layout to measure" (jsdom, and any non-visual environment),+ // not "the scrollbar is as wide as the window".+ if (viewportWidth === 0) {+ return NOOP;+ }++ const previousGutter = root.style.scrollbarGutter;+ const previousPadding = element.style.paddingRight;+ const widthBefore = element.getBoundingClientRect().width;++ let heldGutter = false;+ let padded = false;+ let settled = false;++ // Only when a space-taking scrollbar is actually there. Holding the gutter+ // open on a page that never had one would carve out 15px that was never+ // reserved — the same shift, in the other direction.+ if (window.innerWidth > viewportWidth) {+ root.style.scrollbarGutter = 'stable';+ heldGutter = true;+ }++ return {+ settle() {+ if (settled) {+ return;+ }+ settled = true;++ // What the lock actually did to this element, rather than what we+ // assumed it would do. 0 on any engine where the gutter held — and on a+ // page that already sets `scrollbar-gutter: stable` itself, where the+ // scrollbar was never taking the space back.+ const grew = element.getBoundingClientRect().width - widthBefore;+ if (grew <= 0) {+ return;+ }++ const existing =+ Number.parseFloat(window.getComputedStyle(element).paddingRight) || 0;+ element.style.paddingRight = `${existing + grew}px`;+ padded = true;+ },++ release() {+ if (padded) {+ element.style.paddingRight = previousPadding;+ padded = false;+ }+ if (heldGutter) {+ root.style.scrollbarGutter = previousGutter;+ heldGutter = false;+ }+ },+ };+}diff --git a/packages/core/src/hooks/useScrollLock.doc.mjs b/packages/core/src/hooks/useScrollLock.doc.mjsindex dd48079dfc..4432c6623a 100644--- a/packages/core/src/hooks/useScrollLock.doc.mjs+++ b/packages/core/src/hooks/useScrollLock.doc.mjs@@ -4,7 +4,7 @@export const docs = {name: 'useScrollLock',displayName: 'useScrollLock',- keywords: ['scroll', 'lock', 'modal', 'dialog', 'body', 'prevent', 'background', 'ios', 'safari', 'fixed'],+ keywords: ['scroll', 'lock', 'modal', 'dialog', 'body', 'prevent', 'background', 'ios', 'safari', 'fixed', 'scrollbar', 'gutter', 'layout shift', 'reflow'],params: [{name: 'isLocked',@@ -16,7 +16,7 @@ export const docs = {returns: [],usage: {description:- 'Locks body scroll when active by pinning the body with position: fixed. This prevents background scrolling behind modals and dialogs, which is necessary for iOS Safari where overscroll-behavior: contain does not work. Restores the original scroll position when unlocked.',+ 'Locks body scroll when active by pinning the body with position: fixed. This prevents background scrolling behind modals and dialogs, which is necessary for iOS Safari where overscroll-behavior: contain does not work. Restores the original scroll position when unlocked. Pinning hides the document scrollbar, so where that scrollbar takes layout space (desktop) the hook holds its gutter open with scrollbar-gutter: stable for the duration of the lock — the page, including any position: fixed chrome, does not shift sideways.',bestPractices: [{ guidance: true, description: 'Use when opening full-screen modals or dialogs to prevent background content from scrolling.' },{ guidance: true, description: 'Pass the same boolean that controls dialog visibility (e.g., isOpen) as the isLocked parameter.' },@@ -32,13 +32,13 @@ export const docs = {/** @type {import('@astryxdesign/cli/authoring').HookTranslationDoc} */export const docsDense = {description:- 'Locks body scroll when active by pinning body w/ position: fixed. Prevents background scrolling behind modals + dialogs, necessary for iOS Safari where overscroll-behavior: contain does not work. Restores original scroll position when unlocked.',+ 'Locks body scroll when active by pinning body w/ position: fixed. Prevents background scrolling behind modals + dialogs, necessary for iOS Safari where overscroll-behavior: contain does not work. Restores original scroll position when unlocked. Holds the hidden scrollbar\'s gutter open (scrollbar-gutter: stable) so the page — incl. position: fixed chrome — does not shift sideways.',paramDescriptions: {isLocked: 'whether body scroll should be locked.',},usage: {description:- 'Locks body scroll when active by pinning body w/ position: fixed. Prevents background scrolling behind modals + dialogs, necessary for iOS Safari where overscroll-behavior: contain does not work. Restores original scroll position when unlocked.',+ 'Locks body scroll when active by pinning body w/ position: fixed. Prevents background scrolling behind modals + dialogs, necessary for iOS Safari where overscroll-behavior: contain does not work. Restores original scroll position when unlocked. Holds the hidden scrollbar\'s gutter open (scrollbar-gutter: stable) so the page — incl. position: fixed chrome — does not shift sideways.',bestPractices: [{ guidance: true, description: 'Use when opening full-screen modals / dialogs to prevent background content from scrolling.' },{ guidance: true, description: 'Pass same boolean that controls dialog visibility (e.g. isOpen) as isLocked parameter.' },diff --git a/packages/core/src/hooks/useScrollLock.test.ts b/packages/core/src/hooks/useScrollLock.test.tsindex 8ea6bc2ff2..c305b82d55 100644--- a/packages/core/src/hooks/useScrollLock.test.ts+++ b/packages/core/src/hooks/useScrollLock.test.ts@@ -17,6 +17,9 @@ describe('useScrollLock', () => {afterEach(() => {cleanup();document.body.style.cssText = '';+ document.documentElement.style.cssText = '';+ // @ts-expect-error -- drop the viewport stub so jsdom's own value comes back+ delete document.documentElement.clientWidth;vi.restoreAllMocks();});@@ -69,4 +72,74 @@ describe('useScrollLock', () => {expect(document.body.style.left).toBe('');expect(document.body.style.right).toBe('');});++ it('holds the page still across the scrollbar it hides', () => {+ // A 1024px window over a 1009px layout viewport = a 15px classic+ // scrollbar. Pinning the body hides it, which would widen the page by+ // those 15px and reflow everything sideways.+ Object.defineProperty(window, 'innerWidth', {+ value: 1024,+ configurable: true,+ writable: true,+ });+ Object.defineProperty(document.documentElement, 'clientWidth', {+ value: 1009,+ configurable: true,+ });+ vi.spyOn(window, 'scrollTo').mockImplementation(() => {});++ const lock = renderHook(() => useScrollLock(true));++ expect(document.documentElement.style.scrollbarGutter).toBe('stable');++ lock.unmount();++ expect(document.documentElement.style.scrollbarGutter).toBe('');+ });++ it('leaves the page alone when the scrollbar is an overlay one', () => {+ Object.defineProperty(window, 'innerWidth', {+ value: 1024,+ configurable: true,+ writable: true,+ });+ Object.defineProperty(document.documentElement, 'clientWidth', {+ value: 1024,+ configurable: true,+ });+ vi.spyOn(window, 'scrollTo').mockImplementation(() => {});++ const lock = renderHook(() => useScrollLock(true));++ expect(document.documentElement.style.scrollbarGutter).toBe('');+ expect(document.body.style.paddingRight).toBe('');++ lock.unmount();+ });++ it('holds the gutter for the outermost overlay only, and gives it back once', () => {+ Object.defineProperty(window, 'innerWidth', {+ value: 1024,+ configurable: true,+ writable: true,+ });+ Object.defineProperty(document.documentElement, 'clientWidth', {+ value: 1009,+ configurable: true,+ });+ vi.spyOn(window, 'scrollTo').mockImplementation(() => {});++ const first = renderHook(() => useScrollLock(true));+ const second = renderHook(() => useScrollLock(true));++ expect(document.documentElement.style.scrollbarGutter).toBe('stable');++ first.unmount();++ expect(document.documentElement.style.scrollbarGutter).toBe('stable');++ second.unmount();++ expect(document.documentElement.style.scrollbarGutter).toBe('');+ });});diff --git a/packages/core/src/hooks/useScrollLock.ts b/packages/core/src/hooks/useScrollLock.tsindex 74b1711892..a9c042f50c 100644--- a/packages/core/src/hooks/useScrollLock.ts+++ b/packages/core/src/hooks/useScrollLock.ts@@ -13,9 +13,11 @@** SYNC: When modified, update:* - /packages/core/src/hooks/index.ts+ * - /packages/core/src/hooks/scrollbarGutter.ts*/import {useEffect} from 'react';+import {holdScrollbarGutter, type ScrollbarGutterHold} from './scrollbarGutter';interface ScrollLockSnapshot {scrollX: number;@@ -25,6 +27,7 @@ interface ScrollLockSnapshot {top: string;left: string;right: string;+ gutter: ScrollbarGutterHold;}let lockCount = 0;@@ -38,6 +41,10 @@ let originalBodyState: ScrollLockSnapshot | null = null;* does not prevent body scroll behind modals. Restores scroll position* on unlock.*+ * Pinning also hides the document's scrollbar, so the gutter that scrollbar+ * occupied is held open for the duration of the lock — without it the page+ * reflows sideways by ~15px the moment an overlay opens.+ ** @example* ```* useScrollLock(isOpen);@@ -55,6 +62,9 @@ export function useScrollLock(isLocked: boolean): void {const scrollX = window.scrollX;const scrollY = window.scrollY;+ // Taken before the pinning styles below hide the scrollbar.+ const gutter = holdScrollbarGutter(body);+originalBodyState = {scrollX,scrollY,@@ -63,6 +73,7 @@ export function useScrollLock(isLocked: boolean): void {top: body.style.top,left: body.style.left,right: body.style.right,+ gutter,};body.style.overflow = 'hidden';@@ -70,6 +81,8 @@ export function useScrollLock(isLocked: boolean): void {body.style.top = `-${scrollY}px`;body.style.left = '0';body.style.right = '0';++ gutter.settle();}lockCount += 1;@@ -89,6 +102,7 @@ export function useScrollLock(isLocked: boolean): void {body.style.top = state.top;body.style.left = state.left;body.style.right = state.right;+ state.gutter.release();window.scrollTo(state.scrollX, state.scrollY);};}, [isLocked]);