Skip to content

Stop every keystroke from querying the whole page for the shortcut recorder - #1028

Open
zcy22606 wants to merge 1 commit into
hardbeat920:mainfrom
zcy22606:fix/keydown-recorder-check
Open

zcy22606 wants to merge 1 commit into
hardbeat920:mainfrom
zcy22606:fix/keydown-recorder-check

Conversation

@zcy22606

@zcy22606 zcy22606 commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

What changed

The workspace keydown handler checks whether the focused element is the active shortcut recorder (document.activeElement?.getAttribute("data-shortcut-recorder-active") === "true") instead of running document.querySelector('[data-shortcut-recorder-active="true"]') on every key.

Why

That query runs before anything else in the handler, on every keystroke, including IME composition keys. An attribute selector has no id/class fast path, so WebKit walks the whole DOM each time, and the DOM grows with every open transcript. In a profile of a real window while typing (macOS sample/Time Profiler of the WebContent process, long sessions open), the query accounted for about 145 ms of a 10 s typing sample.

The check is equivalent: the recorder is the <input data-shortcut-recorder-active> in the keybinding settings row, which starts recording in onFocus and stops in onBlur, so it is active exactly when it is the focused element.

UI

No visible change.

Validation

  • npm run check:web: vitest (5363 passed, 13 skipped) and tsc --noEmit. No Rust changes.
  • No new test: this lives in Workspace's inline keydown effect, and the behaviour (the recorder still swallows chords while recording) is unchanged by construction. Happy to add one if you'd like it covered.

Checklist

  • I ran npm run check (check:web; no Rust files changed)
  • This PR is small and focused
  • I did not mix unrelated changes

Summary by CodeRabbit

  • Bug Fixes
    • Keyboard shortcut handling now checks whether the focused control is actively recording a shortcut. Shortcuts are suppressed while focus is on that control, but are no longer blocked simply because an unrelated shortcut recorder is active elsewhere on the page. This keeps shortcut behavior aligned with the control the user is currently interacting with.

…corder

The workspace keydown handler ran
document.querySelector('[data-shortcut-recorder-active="true"]') before
anything else, on every key including IME composition keys. An attribute
selector has no fast path, so each keystroke walked the whole DOM, which
grows with the open transcripts.

The recorder input begins recording on focus and stops on blur, so the
recorder is active exactly when it is the focused element: check
document.activeElement instead.
@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 34072ca3-dd53-46eb-b9fa-be8614ee5513
📥 Commits

Reviewing files that changed from the base of the PR and between e49a5ae and 05e5bb7.

📒 Files selected for processing: 1
  • src/app/App.tsx

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

📝 Walkthrough

The key handler now checks the focused element’s data-shortcut-recorder-active attribute. It returns early when the attribute is "true".

Changes: Shortcut-recorder key handling

Layer / File(s) Summary
Check the focused element
src/app/App.tsx
The key handler checks the focused element’s data-shortcut-recorder-active attribute. It no longer returns early because another element in the document has that attribute set to "true".

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~5 minutes

Change: Refactor

Suggested reviewers: hardbeat920

Merge Risk: ⚪ Minimal · up to 05e5b

The change avoids a document-wide recorder lookup on each keystroke, and the recorder’s focus lifecycle preserves the shortcut guard. No actionable merge risk remains.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description check Passed The description includes all required sections, explains the change and reason, states that there is no UI change, and confirms the checklist items. It also documents validation results and the absenc…
Title check Passed The title clearly and concisely describes the main change: preventing each keystroke from querying the full page for the shortcut recorder.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description includes all required sections, explains the change and reason, states that there is no UI change, and confirms the checklist items. It also documents validation results and the absence of new tests.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

1 participant