From 1041b13f53ccc9954ca211d98dcec86c6ad06a3c Mon Sep 17 00:00:00 2001 From: Dongyu <121479194+dongyu-will@users.noreply.github.com> Date: Thu, 3 Sep 2026 15:30:11 +0800 Subject: [PATCH] fix(web): keep settings scrolling inside its pane (#1160) Co-authored-by: Bingxi Zhao (Frank) <13051345080@163.com> --- .../settings/navigation/settings-scroll.ts | 13 +++++-- web/tests/e2e/settings-navigation.audit.ts | 35 +++++++++++++++++++ .../settings-continuous-navigation.test.ts | 2 ++ 3 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 web/tests/e2e/settings-navigation.audit.ts diff --git a/web/features/settings/navigation/settings-scroll.ts b/web/features/settings/navigation/settings-scroll.ts index 194ec38ef..b7e550c2c 100644 --- a/web/features/settings/navigation/settings-scroll.ts +++ b/web/features/settings/navigation/settings-scroll.ts @@ -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; } diff --git a/web/tests/e2e/settings-navigation.audit.ts b/web/tests/e2e/settings-navigation.audit.ts new file mode 100644 index 000000000..9c0c59cff --- /dev/null +++ b/web/tests/e2e/settings-navigation.audit.ts @@ -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); + }); +}); diff --git a/web/tests/settings-continuous-navigation.test.ts b/web/tests/settings-continuous-navigation.test.ts index d1ab97bcd..0063b6d05 100644 --- a/web/tests/settings-continuous-navigation.test.ts +++ b/web/tests/settings-continuous-navigation.test.ts @@ -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", () => {