Skip to content

fix(dismissable): register escape handler synchronously when node is available - #3251

Open
kirthi-b wants to merge 1 commit into
chakra-ui:mainfrom
kirthi-b:fix/dismissable-escape-deferral
Open

fix(dismissable): register escape handler synchronously when node is available#3251
kirthi-b wants to merge 1 commit into
chakra-ui:mainfrom
kirthi-b:fix/dismissable-escape-deferral

Conversation

@kirthi-b

@kirthi-b kirthi-b commented Aug 6, 2026

Copy link
Copy Markdown

Fixes #3248

trackDismissableElement deferred its whole setup by one frame when defer: true, so a just-opened dialog was visible and focus trapped but ignored the Escape key until the next animation frame. Under CPU load that window stretches well past one frame.

The deferral only exists so the node can be resolved lazily, and the interact-outside logic already defers itself internally via its own defer option. This change resolves the node eagerly and registers handlers synchronously when it is available, keeping the deferred pass only as a fallback for nodes that have not rendered yet. The opening click still cannot dismiss the layer, and nested layers keep their stacking order since layerStack.add now runs before any later child registers.

Added unit tests covering immediate escape dismissal, the deferred fallback, topmost-only dismissal with nested layers, and cleanup.

…available

trackDismissableElement deferred its entire setup by one frame when
defer: true, so a just-opened dialog was visible and focus-trapped but
could not be dismissed with the escape key until the next animation
frame. The deferral only exists so the node can be resolved lazily;
the interact-outside logic already defers itself internally.

Resolve the node eagerly and register handlers synchronously when it
is available, keeping the deferred pass only as a fallback for nodes
that have not rendered yet.

Fixes chakra-ui#3248
@vercel

vercel Bot commented Aug 6, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
zag-nextjs Ready Ready Preview Aug 6, 2026 4:31pm
zag-solid Ready Ready Preview Aug 6, 2026 4:31pm
zag-svelte Ready Ready Preview Aug 6, 2026 4:31pm
zag-vue Ready Ready Preview Aug 6, 2026 4:31pm
zag-website Ready Ready Preview Aug 6, 2026 4:31pm

Request Review

@changeset-bot

changeset-bot Bot commented Aug 6, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 6f1811b

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

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.

dismissable: Escape handler is deferred a frame for no reason, leaving dialogs undismissable while visible

1 participant