Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions packages/core/src/MobileNav/MobileNavCloseEdgeCases.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,65 @@ describe('MobileNav close path edge cases', () => {
expect(document.documentElement.style.overflow).toBe('');
});

it('releases the page when the dialog closed natively before isOpen turned false', () => {
vi.useFakeTimers();
// A classic scrollbar, so the lock holds the gutter: jsdom does no layout.
const innerWidth = Object.getOwnPropertyDescriptor(window, 'innerWidth');
const css = Object.getOwnPropertyDescriptor(window, 'CSS');
Object.defineProperty(window, 'innerWidth', {
value: 1024,
configurable: true,
writable: true,
});
Object.defineProperty(document.documentElement, 'clientWidth', {
value: 1009,
configurable: true,
});
Object.defineProperty(window, 'CSS', {
value: {
supports: (property: string, value: string) =>
property === 'scrollbar-gutter' && value === 'stable',
},
configurable: true,
writable: true,
});
try {
const {rerender} = render(<Drawer isOpen />);
const dialog = screen.getByTestId<HTMLDialogElement>('mobile-nav');
// Whatever value the lock writes, the page is locked while open.
expect(document.documentElement.style.overflow).not.toBe('');
expect(document.documentElement.style.scrollbarGutter).toBe('stable');

// A `<form method="dialog">` submit or a close() through a ref closes
// the dialog before the app's state follows.
act(() => {
dialog.close();
});
act(() => {
rerender(<Drawer isOpen={false} />);
});
act(() => {
vi.advanceTimersByTime(2000);
});

expect(document.documentElement.style.overflow).toBe('');
expect(document.documentElement.style.scrollbarGutter).toBe('');

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.

This assertion cannot fail: jsdom reports documentElement.clientWidth as 0, so holdScrollbarGutter returns its no-op and scrollbarGutter is already '' while the drawer is open. Stubbing a classic scrollbar (as stubViewport(1024, 1009) with CSS.supports('scrollbar-gutter', 'stable') in MobileNavScrollbarGutter.test.tsx) and asserting stable before the close would make the gutter half of the case real.

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.

Fixed at 0a17209: the case stubs a classic scrollbar, as MobileNavScrollbarGutter.test.tsx does, and asserts stable while open and '' after the native close. A control without the lock's gutter release fails here.

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.

Non-blocking: the current component:MobileNav FR3 releases three things on close, and the lock writes overscroll-behavior-y: none on the root and <body> in the same claim as the overflow. These two lines after this one pass today and would pin the third release on the native-close path:

expect(document.documentElement.style.overscrollBehaviorY).toBe('');
expect(document.body.style.overscrollBehaviorY).toBe('');

} finally {
vi.useRealTimers();
if (innerWidth) {
Object.defineProperty(window, 'innerWidth', innerWidth);
}
// @ts-expect-error -- drop the stub so jsdom's own value comes back
delete document.documentElement.clientWidth;
if (css) {
Object.defineProperty(window, 'CSS', css);
} else {
// @ts-expect-error -- jsdom has no CSS object of its own
delete window.CSS;
}
}
});

it('leaves no pending close timer behind after unmount', () => {
vi.useFakeTimers();
try {
Expand Down
Loading