fix(web): keep settings scrolling inside its pane (#1160)

Co-authored-by: Bingxi Zhao (Frank) <13051345080@163.com>
This commit is contained in:
Dongyu
2026-09-03 15:30:11 +08:00
committed by GitHub
parent d3999b7d62
commit 1041b13f53
3 changed files with 47 additions and 3 deletions

View File

@@ -39,8 +39,15 @@ export function scrollToSettingsSection(
scroller.scrollTo({ top: Math.max(0, top), behavior });
// Fragment navigation may have moved the root scrolling element before the
// client handler ran. Keep the full-height application shell pinned.
window.scrollTo({ top: 0, left: 0, behavior: "auto" });
// Fragment navigation may move the root scrolling element before or after
// the client handler runs. Keep the full-height application shell pinned
// now and after the anchor's default-action frame.
const resetDocumentScroll = () => {
window.scrollTo({ top: 0, left: 0, behavior: "auto" });
document.documentElement.scrollTop = 0;
document.body.scrollTop = 0;
};
resetDocumentScroll();
requestAnimationFrame(resetDocumentScroll);
return true;
}

View File

@@ -0,0 +1,35 @@
import { expect, test } from "@playwright/test";
test.describe("Settings navigation", () => {
test("keeps scrolling inside the settings pane", async ({ page }) => {
await page.goto("/settings");
const settingsScroll = page.locator("[data-settings-scroll]");
await expect(settingsScroll).toBeVisible();
await expect.poll(() => page.evaluate(() => window.scrollY)).toBe(0);
const aboutLink = page.locator('a[data-tour="tour-nav-about"]');
await aboutLink.click();
await expect(page).toHaveURL(/\/settings#about$/);
await expect
.poll(() => settingsScroll.evaluate((element) => element.scrollTop))
.toBeGreaterThan(0);
await expect.poll(() => page.evaluate(() => window.scrollY)).toBe(0);
});
test("keeps deep-link scrolling inside the settings pane", async ({
page,
}) => {
await page.goto("/settings#about");
const settingsScroll = page.locator("[data-settings-scroll]");
await expect(settingsScroll).toBeVisible();
await expect(page).toHaveURL(/\/settings#about$/);
await expect
.poll(() => settingsScroll.evaluate((element) => element.scrollTop))
.toBeGreaterThan(0);
await expect.poll(() => page.evaluate(() => window.scrollY)).toBe(0);
});
});

View File

@@ -83,6 +83,8 @@ test("settings scroll: the outer document tracks nested section anchors", () =>
);
assert.match(scrollHelper, /scroller\.scrollTo/);
assert.match(scrollHelper, /window\.scrollTo/);
assert.match(scrollHelper, /document\.documentElement\.scrollTop = 0/);
assert.match(scrollHelper, /requestAnimationFrame\(resetDocumentScroll\)/);
});
test("settings page: heavy sections are split and mounted on demand", () => {