From bee00457e9ead57a6a96030fb2d94be58112e216 Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Mon, 20 Jul 2026 10:54:11 -0400 Subject: [PATCH] fix(v2): ignore phantom/non-standard gamepads in nav polling The v2 gamepad polling loop reads buttons and axes by hardcoded W3C standard-mapping indices, but only guarded against null pads. Firefox (and Zen) expose phantom or non-standard-mapping gamepads even with no real controller attached, whose analog controls drift across the press threshold. Index 4/5 (LB/RB) are bound to AppNav section cycling, so each oscillation re-fired cycleSection and looped the app through home/platforms/collections/search with no user input, making the UI unusable. Add an isUsablePad() guard requiring pad.connected and a "standard" mapping, applied in both the polling loop and detectPadPresence. Every button/axis read assumes the standard mapping, so a non-standard pad cannot be interpreted safely regardless. Fixes #3851 Co-Authored-By: Claude Opus 4.8 (1M context) --- .../src/v2/composables/useGamepad/index.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/frontend/src/v2/composables/useGamepad/index.ts b/frontend/src/v2/composables/useGamepad/index.ts index 0e9ffa1c3..5e1bbe20f 100644 --- a/frontend/src/v2/composables/useGamepad/index.ts +++ b/frontend/src/v2/composables/useGamepad/index.ts @@ -104,6 +104,16 @@ const BUTTON_MAP: Record = { 15: { key: "ArrowRight", code: "ArrowRight" }, }; +// Guards the polling loop against phantom / non-standard pads. All button +// and axis reads use W3C standard-mapping indices, so a pad that is +// disconnected or reports a non-standard mapping cannot be interpreted +// safely. Firefox surfaces such devices and their analog drift would +// otherwise trigger index-based actions (e.g. LB/RB section cycling) on +// their own. See issue #3851. +function isUsablePad(pad: Gamepad | null): pad is Gamepad { + return pad !== null && pad.connected && pad.mapping === "standard"; +} + function dispatchKey(binding: Binding) { const target = (document.activeElement as HTMLElement | null) ?? document.body; @@ -229,7 +239,7 @@ export function useGamepad() { // or first button press takes over. function detectPadPresence() { const list = navigator.getGamepads?.() ?? []; - const hasPad = Array.from(list).some((p) => p !== null); + const hasPad = Array.from(list).some((p) => isUsablePad(p)); if (hasPad && !everSawPad) { everSawPad = true; setModality("pad"); @@ -257,7 +267,12 @@ export function useGamepad() { const actionsDisabled = ACTIONS_DISABLED_PATHS.has(route.path); for (const pad of pads) { - if (!pad) continue; + // Only act on connected, standard-mapping pads: every button/axis + // read below is by W3C standard index, so a phantom or non-standard + // pad (Firefox keeps disconnected entries around and reports + // uncalibrated analog controls) would map drifting values onto LB/RB + // and cycle AppNav sections with no user input. See issue #3851. + if (!isUsablePad(pad)) continue; const key = `${pad.index}:${pad.id}`; const st = (states[key] ||= { buttons: {},