fix: use capture-phase keydown listener with escClosingRef to prevent duplicate ESC handling#500
Closed
Copilot wants to merge 1 commit intofix/preview-esc-cifrom
Closed
fix: use capture-phase keydown listener with escClosingRef to prevent duplicate ESC handling#500Copilot wants to merge 1 commit intofix/preview-esc-cifrom
Copilot wants to merge 1 commit intofix/preview-esc-cifrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Copilot
AI
changed the title
[WIP] [WIP] Address feedback on handling Escape in preview keydown
fix: use capture-phase keydown listener with escClosingRef to prevent duplicate ESC handling
Mar 17, 2026
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.
event.stopPropagation()in a bubbling-phasewindow.addEventListener('keydown', ...)handler has no effect ondocument-level listeners (which fire earlier in the bubble chain) or otherwindowbubble listeners. The original fix in #499 used it incorrectly.Changes
window.addEventListener('keydown', onKeyDown, true)so the Preview handler fires before@rc-component/portal'sonGlobalKeyDown(window bubble-phase) and anydocument-level listenersescClosingRefguard: replaces the ineffectivestopPropagation(). When our capture handler callsonClose(), it setsescClosingRef.current = true(reset via microtask) so the Portal'sonEsccallback skips the duplicate close:onEscfallback restored: Portal'sonEscis kept as a safety net for edge cases where focus movement triggers ESC detection outside our window listenerpreview.portal.test.tsxcovers capture-phase registration,onEscfallback, and the deduplication guard🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.