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.

@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 83.20%. Comparing base (82f449a) to head (4506614).

Additional details and impacted files
@@             Coverage Diff             @@
##           master    #9710       +/-   ##
===========================================
+ Coverage   69.68%   83.20%   +13.51%     
===========================================
  Files         629      630        +1     
  Lines       37413    37450       +37     
  Branches     3296     3357       +61     
===========================================
+ Hits        26073    31159     +5086     
+ Misses      11191     5910     -5281     
- Partials      149      381      +232     

☔ 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
…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.
@camd
camd force-pushed the worktree-kbd-shortcut-double-hit branch from 8e5c646 to 4506614 Compare July 31, 2026 17:51
@netlify

netlify Bot commented Jul 31, 2026

Copy link
Copy Markdown

Deploy Preview for treeherder ready!

Name Link
🔨 Latest commit 4506614
🔍 Latest deploy log https://app.netlify.com/projects/treeherder/deploys/6a6ce0b683788d00089f6f36
😎 Deploy Preview https://deploy-preview-9710--treeherder.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

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