Fix comment-typing freeze: scope drag-strum keydown + fix listener leak (#2926)#2929
Open
vitalibondar wants to merge 2 commits into
Open
Fix comment-typing freeze: scope drag-strum keydown + fix listener leak (#2926)#2929vitalibondar wants to merge 2 commits into
vitalibondar wants to merge 2 commits into
Conversation
The drag-and-strum controller adds a global keydown listener to play an instrument while dragging cards. Two issues made typing in the comment editor janky (reported on Safari, basecamp#2926): 1. Listener leak: connect added the handler via handleKeyDown.bind(this) and disconnect tried to remove it with a *different* .bind(this) reference, so the listener was never removed. Every Turbo reconnect added another permanent global keydown listener — they accumulate over a session and all fire on every keystroke. Bind once and reuse the reference so removeEventListener works. 2. Fires while typing: the handler ran on every document keydown, including inside the comment editor. Holding Shift (capital letters) repeatedly hit #preloadAudioFiles, constructing new Audio() in a loop on each keystroke. Ignore keydown originating from text inputs / contenteditable / the lexxy editor — the strum is only meaningful during a drag. Fixes basecamp#2926 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Improves the controller’s global keyboard handling by making event listener cleanup reliable and preventing shortcuts from firing while the user is editing text.
Changes:
- Store a bound
handleKeyDownreference to ensureremoveEventListenerunregisters correctly. - Skip key handling when the event target is an editable/text input element.
- Add a private
#isEditingTexthelper to centralize editability detection.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+72
to
+77
| #isEditingText(element) { | ||
| if (!element) { return false } | ||
| if (element.isContentEditable) { return true } | ||
|
|
||
| return element.closest?.("input, textarea, select, lexxy-editor") != null | ||
| } |
| } | ||
|
|
||
| handleKeyDown(event) { | ||
| if (this.#isEditingText(event.target)) { return } |
Address review feedback on #isEditingText: - Only treat text-entry inputs as editing (skip checkbox/radio/range/file/ button/etc.) so the strum isn't suppressed when a non-text control has focus during a drag. - Fall back to document.activeElement when the event has no target. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Author
|
Thanks — both points were fair, addressed in the latest commit:
|
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.
Fixes #2926 — typing in a card's comment box freezes Safari (macOS + iOS) for 5–10s, worsening over a session.
drag_and_strum_controlleradds a globalkeydownlistener to play an instrument while a card is dragged between columns. Two problems make typing janky:1. Listener leak (
bindreference mismatch).bind(this)returns a new function each time, soremoveEventListenernever matches the listener added inconnect. Every Turbo reconnect leaks another permanent globalkeydownlistener; they accumulate over a session and all fire on each keystroke. This matches the reported "~15keydownper typed character, worsens during a session".Fix: bind once, store the reference, reuse it for add/remove.
2. Handler runs while typing
The handler fired on every document
keydown, including inside the comment editor. Typing capital letters / shifted keys (event.shiftKey) repeatedly hit#preloadAudioFiles, constructingnew Audio()in a loop on each keystroke. The strum is only meaningful during a drag, so keydown originating from a text field /contenteditable/ thelexxy-editoris now ignored via a small#isEditingTextguard (isContentEditable+closest("input, textarea, select, lexxy-editor")).Notes
node --checkpasses. The diagnosis and profiling are in Typing in comments freezes Safari: global keydown in drag_and_strum + heavy compositing #2926.🤖 Generated with Claude Code