Skip to content

fix(drawer): fire onExitComplete when overlay turns off mid-fade - #517

Open
ispashkov wants to merge 6 commits into
mainfrom
fix/drawer-exit-complete
Open

ispashkov wants to merge 6 commits into
mainfrom
fix/drawer-exit-complete

Conversation

@ispashkov

@ispashkov ispashkov commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

What

Follow-ups to #513 (onExitComplete on Drawer and Dialog), found by a claim-by-claim review of the overlay manager design (#514):

  • Bug: overlay turning off mid-fade. When overlay flips to false after the panel's exit but while the backdrop still fades (overlay={!isMobile} during a resize), the backdrop unmounted without reporting, so onExitComplete never fired. While closed, the drawer now keeps the overlay value it was last open with; a change applies on the next open. Drawer and Dialog both.
  • Flaky e2e. Drawer.e2e.ts › "Should report one finished exit per close" was retried as flaky on main (run 44301136351) and on feat(overlay-manager): open the same Dialog or Drawer from anywhere #514 (run 44295252899). zag attaches the Escape listener a microtask or a frame after the content shows, so an Escape pressed as soon as the panel was visible was sometimes lost. The exit tests now press Escape once focus is inside the drawer.
  • Browser proof of the backdrop wait. The e2e test now reads the count when the closed backdrop's fade ends, from a capture listener that runs before zag ends that exit: it must still show the previous count. A callback fired at the end of the panel's shorter exit fails it. Before, the test counted calls only, which also passed for that regression.
  • Backdrop test id. The backdrop gets {id}--overlay from the test-id cascade, as the test-id rules require of every part; the check above locates it that way.
  • JSDoc. It said onExitComplete fires "right away when there is no animation"; on zag 1.43.3 it fires about a frame after the close, and at once only in a tab that is already hidden. It now also says that a tab hidden mid-exit can delay it, and that a drawer inside another one's content does not fire when the outer one closes and unmounts it.
  • Guideline. detail-drawer.md points at onExitComplete for resetting state after the close.

Additive: no breaking change, no migration.

Test plan

  • Drawer and Dialog unit tests: 60 passed, 2 of them new (the overlay flip, on Drawer and on Dialog). The new test failed before the fix (Tests 2 failed) and passes after it
  • Full design-system suite: 322 files passed (2 skipped), 4023 tests passed (37 skipped), no retries
  • pnpm lint, pnpm typecheck, tsc --build tsconfig.app.json --noEmit, and the guideline word budgets
  • compiler:audit: no bailout in DrawerProvider.tsx or DrawerOverlay.tsx; its one Drawer entry, DrawerResizeHandle.tsx, predates this PR
  • The new browser assertion checked against a mutant in jsdom: with DrawerRoot patched to report on the panel alone, the recorded count reads Exits finished: 1 and the check fails
  • CI green (run 44351631267), with no flaky e2e test; the exit test had needed a retry in both earlier runs it was in

🤖 Generated with Claude Code

ispashkov and others added 6 commits November 18, 2026 20:32
…e drawer

zag registers the dialog's dismissable layer, and its Escape listener,
up to a frame after the panel mounts. The exit tests pressed Escape as
soon as the panel was visible, so a press could land first and be lost:
'Should report one finished exit per close' failed its first attempt in
CI on main and on another branch. The listener is in place no later
than the frame that moves focus into the panel, so wait for that.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DrawerOverlay was the one Drawer sub-component without the test id
cascade, so tests could reach the backdrop only through zag's
data-part. With a root data-testid it now renders {id}--overlay, on
Drawer and on Dialog, which shares it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ckdrop

The exit e2e only counted calls, which also passes when the callback
fires at the end of the panel's shorter exit. Read the count in a
document capture listener as the closed backdrop's fade ends: it runs
before zag's own listener, which ends the exit, so it must still show
the previous count. A panel-only build reads the bumped one there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The JSDoc said it fires right away when nothing animates; it fires about
a frame after the close, and at once only in a hidden tab. It now also
says that a tab hidden mid-exit can hold the callback until the tab is
shown again, and that a drawer inside another one's content unmounts
without firing when the outer one closes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Once the panel has finished its exit, the callback waits for the
backdrop. Turning overlay off in that window (overlay={!isMobile} during
a resize) unmounted the backdrop before its exit ended, so zag never
reported it and onExitComplete never fired for that close. While
closed, the provider now keeps the overlay value the drawer was last
open with, so the backdrop fades out and reports; a change applies on
the next open. Dialog shares the provider and gets the same fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The guideline taught only the latch: keep the last entity after close so
the content does not blank. It now says to reset state after the close
in onExitComplete, which fires once the exit animation ends.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

This PR is included in version 4.20.2-rc-fix-drawer-exit-complete.1

This branch has not been deployed

No deployments
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