From bab1b30009a204354c30721136854d1ba2c8edd5 Mon Sep 17 00:00:00 2001 From: yetone Date: Wed, 14 Oct 2026 18:59:38 +0800 Subject: [PATCH] routing: the hub's mode chip is written only when it changes, so a press held over the once-a-second redraw still clicks in WebKit (#2151) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cause: the routing view redraws every second (setInterval → render → header). header() set chip.textContent and goTo() re-set data-go, tabindex, role and title each time, even when nothing changed. Setting textContent swaps the chip's text node. In WebKit, a press whose mousedown and mouseup straddle that swap gets no click, so goRouting never ran and routing-mode-goes timed out waiting for .rt-found (webkit zh 420 on CI). A reader pressing the chip for a moment could miss it the same way. Reproduced by injecting a delay: SIGSTOP/SIGCONT duty-cycling of WebKit's UI process. At 10ms on / 490ms off, a MutationObserver on .rt-hub plus pointer logging showed pointerdown at 2407ms, the hub's childList swap at 2869ms, pointerup at 2904ms, and no click. At 50/450, 1 of 30 runs timed out at the rt-found wait on the old code; 0 of 30 do with this change. Fix: header() and hubText() go through setText (write only if different), and goTo() sets each attribute only when it differs. The activity list's heading chips already keep equal nodes through patch(). Test: routing-mode-goes now holds a press over one redraw. It counts the routing interval's ticks through a wrapped setInterval, then does mouse.down, waits for a tick, does mouse.up and expects .rt-found. On the old routing.js this fails in all 10 WebKit cases at that wait (chromium passes, since it clicks the common ancestor); with the fix it passes. Run (playwright 1.62.0, chromium + webkit): - routing-mode-goes: 40/40, en zh zh-TW ja de at 1100 and 420. - group-switch-add-many, group-share, routing-key-windows, routing-weight-chip, view-scrollbar-drag, routing-steady, routing-idle-frame and routing-shape all pass. - routing-live-patch failed one folded subtest only with 9 files run at once. It passes 2/2 alone with and without this change: a fixed 400ms sample, filed as #2174. Not tried: the desktop app's WKWebView by hand. At 2% CPU (10/490) the chip now clicks, but the view's scroll guard can still refuse or put back the scroll when the click is handled more than 1s late. I left that alone; it doesn't appear at 10%. --- internal/gui/assets/routing.js | 16 +++++++++------ internal/gui/tests/routing-mode-goes.test.cjs | 20 +++++++++++++++++++ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/internal/gui/assets/routing.js b/internal/gui/assets/routing.js index 1a2bd950c..168c09544 100644 --- a/internal/gui/assets/routing.js +++ b/internal/gui/assets/routing.js @@ -1471,7 +1471,10 @@ const on = r.order.filter((x) => !x.fallback).length; const pool = !g && f ? poolOf(f.provider) : null; const lone = !g && on <= 1 && !pool; - chip.textContent = t(m[0]); + // the head is told again every second: a chip whose text node is + // swapped while it is pressed gets no click in WebKit (#2151), so + // only what changed is written + setText(chip, t(m[0])); chip.hidden = lone; goTo(chip, g ? "group:" + g.id : pool ? "pool:" + f.provider : "", g ? g.name : f?.name || r.provider); hubText(); @@ -1484,12 +1487,13 @@ // goTo makes what names a routing a way to where it is set: a provider's // own under Several accounts or keys, a group's its card function goTo(e, go, name) { - e.dataset.go = go; e.classList.toggle("rt-go", !!go); if (go) { - e.tabIndex = 0; - e.setAttribute("role", "button"); - e.title = t("Change how {name} routes", { name }); + const title = t("Change how {name} routes", { name }); + if (e.dataset.go !== go) e.dataset.go = go; + if (e.tabIndex !== 0) e.tabIndex = 0; + if (e.getAttribute("role") !== "button") e.setAttribute("role", "button"); + if (e.title !== title) e.title = title; } else for (const a of ["data-go", "tabindex", "role", "title"]) e.removeAttribute(a); } function goRouting(e, go) { @@ -3209,7 +3213,7 @@ } } - function hubText() { hubSub.textContent = (providers?.gateway?.url || "").replace(/^https?:\/\//, "") || t("gateway"); } + function hubText() { setText(hubSub, (providers?.gateway?.url || "").replace(/^https?:\/\//, "") || t("gateway")); } // labels in the page's language, and again when it changes function words() { diff --git a/internal/gui/tests/routing-mode-goes.test.cjs b/internal/gui/tests/routing-mode-goes.test.cjs index 90937e6cd..41da04c7e 100644 --- a/internal/gui/tests/routing-mode-goes.test.cjs +++ b/internal/gui/tests/routing-mode-goes.test.cjs @@ -74,6 +74,12 @@ async function open(engine, lang, scene, width, t) { page.setDefaultTimeout(5000); const errors = []; page.on("pageerror", (error) => errors.push(error.message)); + // counts the routing view's once-a-second redraws, to hold a press over one + await page.addInitScript(() => { + const every = window.setInterval; + window.__redraws = 0; + window.setInterval = (f, ms, ...a) => every(typeof f === "function" && String(f).includes("renderActs") ? (...x) => { f(...x); window.__redraws++; } : f, ms, ...a); + }); await page.route("**/*", serve(lang, scene)); await page.goto("http://magpie.test/?view=routing"); const req = page.locator(".rt-req").first(); @@ -130,6 +136,20 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", assert.equal(await page.evaluate(() => document.activeElement?.classList.contains("on")), true); assert.equal((await page.evaluate(() => document.activeElement.textContent)).trim(), smart[lang]); + // a press held over the head's redraw is still a click (#2151): the + // chip is not written over under the pointer, which WebKit takes + // for a press that never ends where it began + await view.evaluate((v) => { v.scrollTop = 0; }); + await pool.evaluate((p) => p.classList.remove("rt-found")); + const box = await chip.boundingBox(); + await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2); + await page.mouse.down(); + const drawn = await page.evaluate(() => window.__redraws); + await page.waitForFunction((n) => window.__redraws > n, drawn, { polling: 50 }); + await page.mouse.up(); + await page.waitForFunction(() => document.querySelector('.rt-pool[data-provider="relay"]')?.classList.contains("rt-found")); + assert.equal(await inView(), true); + // the keyboard does the same from the top await view.evaluate((v) => { v.scrollTop = 0; }); await chip.focus();