Fix keyboard shortcuts needing a second press after opening a log or profile#9710
Open
camd wants to merge 1 commit into
Open
Fix keyboard shortcuts needing a second press after opening a log or profile#9710camd wants to merge 1 commit into
camd wants to merge 1 commit into
Conversation
…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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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>fromreact-hot-keys(ui/job-view/KeyboardShortcuts.jsx). That library keeps an internalisKeyDownlatch to suppress key-repeat:keydownsets the latchtrue(and swallows any further keydown while it's set);keyupthat bubbles todocument.body.Three shortcuts open a new browser tab/window, moving focus off the page so their
keyupis delivered to the new tab and never reachesdocument.body:ltarget="_blank"link)shift+ltarget="_blank"link)gwindow.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
keyupondocument.body, so the next shortcut fires on the first press. This is general — it also covers alt-tabbing away or anywindow.openwhile a key is held.Testing
tests/ui/job-view/KeyboardShortcuts_test.jsx, which reproduces the stuck-latch (second keydown with no intervening keyup is swallowed) and verifies recovery after ablur.react-hot-keysinstance, 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 awindowblur fired again. Normal press→release→press cycles continue to fire on the first press.PinBoard_test.jsx(also rendersKeyboardShortcuts) still passes.