Skip to content

Fix keyboard shortcuts needing a second press after opening a log or profile#9710

Open
camd wants to merge 1 commit into
masterfrom
worktree-kbd-shortcut-double-hit
Open

Fix keyboard shortcuts needing a second press after opening a log or profile#9710
camd wants to merge 1 commit into
masterfrom
worktree-kbd-shortcut-double-hit

Conversation

@camd

@camd camd commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

Problem

Some job-view keyboard shortcuts intermittently have to be pressed twice to take effect.

Root cause

The job view wraps all shortcuts in a single <Hotkeys> from react-hot-keys (ui/job-view/KeyboardShortcuts.jsx). That library keeps an internal isKeyDown latch to suppress key-repeat:

  • a keydown sets the latch true (and swallows any further keydown while it's set);
  • the latch is only cleared by a keyup that bubbles to document.body.

Three shortcuts open a new browser tab/window, moving focus off the page so their keyup is delivered to the new tab and never reaches document.body:

Key Action
l logviewer (target="_blank" link)
shift+l raw log (target="_blank" link)
g gecko profile (window.open(url, '_blank'))

After one of these, the latch stays stuck true, so the next shortcut is silently swallowed and must be pressed a second time.

Fix

Clear the latch when the window loses focus by synthesizing a keyup on document.body, so the next shortcut fires on the first press. This is general — it also covers alt-tabbing away or any window.open while a key is held.

Testing

  • Added tests/ui/job-view/KeyboardShortcuts_test.jsx, which reproduces the stuck-latch (second keydown with no intervening keyup is swallowed) and verifies recovery after a blur.
  • Verified live in the browser against staging data: driving the real react-hot-keys instance, keydown Vagrant dev environment #1 fired, keydown treeherder RDBS schemas #2 (no keyup) was swallowed, and keydown Vagrant dev environment and a django webapp skeleton #3 after a window blur fired again. Normal press→release→press cycles continue to fire on the first press.
  • PinBoard_test.jsx (also renders KeyboardShortcuts) still passes.

…profile

Shortcuts that open a new browser tab (l, shift+l, g) move focus away
from the page, so the keyup for that keypress is delivered to the new
tab instead of the document. react-hot-keys clears its internal
`isKeyDown` latch only on a keyup bubbling to document.body, so the
latch stays stuck `true` and the next shortcut is swallowed by its
key-repeat guard -- forcing the user to press it twice.

Clear the latch when the window loses focus by synthesizing a keyup on
document.body, so the next shortcut fires on the first press.
@codecov-commenter

codecov-commenter commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.66%. Comparing base (835e437) to head (8e5c646).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #9710   +/-   ##
=======================================
  Coverage   82.65%   82.66%           
=======================================
  Files         627      627           
  Lines       36784    36789    +5     
  Branches     3280     3282    +2     
=======================================
+ Hits        30405    30410    +5     
  Misses       6229     6229           
  Partials      150      150           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@camd camd self-assigned this Jul 22, 2026
@camd
camd requested a review from Archaeopteryx July 24, 2026 00:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants