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)
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%.
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user