fix: stop Back doing nothing in Settings after the window crosses the phone width several times

This commit is contained in:
Linus Rath
2026-11-03 15:12:06 +01:00
parent 98286b9995
commit 3687363d6e
2 changed files with 37 additions and 1 deletions
@@ -102,6 +102,37 @@ describe('Settings deep links on the phone', () => {
expect(screen.getByText('appearance pane')).toBeTruthy();
});
it('adds one history entry however often the window crosses the phone breakpoint', () => {
window.history.replaceState(null, '', '/settings');
media.desktop = true;
const { rerender } = render(<SettingsApp linkSegments={[]} />);
const push = vi.spyOn(window.history, 'pushState');
const resize = (desktop: boolean) => {
media.desktop = desktop;
rerender(<SettingsApp linkSegments={[]} />);
};
resize(false);
expect(push).toHaveBeenCalledTimes(1);
resize(true);
resize(false);
resize(true);
resize(false);
expect(push).toHaveBeenCalledTimes(1);
expect(screen.getByText('appearance pane')).toBeTruthy();
// Back from the page lands on the list...
act(() => {
window.history.replaceState(null, '', '/settings');
window.dispatchEvent(new PopStateEvent('popstate'));
});
expect(screen.getByTestId('settings-tab-organize')).toBeTruthy();
// ...and a page opened from there has a Back of its own.
fireEvent.click(screen.getByTestId('settings-tab-organize'));
expect(push).toHaveBeenCalledTimes(2);
});
it('opens a page at its top and keeps the place in the list', () => {
window.history.replaceState(null, '', '/settings');
render(<SettingsApp linkSegments={[]} />);
+6 -1
View File
@@ -517,7 +517,12 @@ export function SettingsApp({ linkSegments: routeSegments }: SettingsAppProps =
window.history.replaceState(window.history.state, '', listPath);
}
}
window.history.pushState({ __settingsSubmenu: true }, '');
// Once per open page: this runs again each time the window crosses the
// phone breakpoint, and the entry from the last crossing is still there.
// Back leaves that entry, so opening a page afterwards adds a new one.
if (!(window.history.state as { __settingsSubmenu?: boolean } | null)?.__settingsSubmenu) {
window.history.pushState({ __settingsSubmenu: true }, '');
}
const handlePop = () => {
setMobileShowContent(false);