Repository navigation
fix(Drawer): stop the panel repainting into the page after close() - #5549
Conversation
`dialog.close()` ran on a hardcoded 250ms timer that had nothing to do with the panel's own transition, and the panel kept rendering afterwards on a discrete `display` transition. For the rest of the hold it therefore painted OUTSIDE the top layer, where any ancestor that establishes a containing block for fixed positioning (`transform`, `filter`, `container-type`, `contain`) becomes the origin of its `position: fixed` — so the panel snapped back into the layout, over content the user had just dismissed it from. Measured on `origin/main` with one `transform: translateZ(0)` on the story root: the panel reaches x=899 at 233ms, then jumps back to x=608 at 250ms and keeps painting until the hold ends. The exit is now driven by the panel's real `transitionend` (backstopped by the duration read off the element, so a theme that rewrites `--duration-medium` is respected instead of assumed), and the hide is flushed in the same task as `close()` so no frame is ever painted outside the top layer. React owns `display` for both legs; the discrete `display` transition is gone. Drive-by in the same file: the container-padding test passed `onClose`, which is not a prop, so `pnpm -F @astryxdesign/lab typecheck` was already red on main.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR Modified ComponentsDrawer (@astryxdesign/lab) · View in Storybook
Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
Open the `Sides` story from `start`, then close it: the panel jumps to the
opposite edge and slides out to the right.
The panel stays mounted for the exit, so the `side` prop is still read during
it — and the idiomatic consumer shape derives `side` from the same state that
drives `isOpen`:
side={side ?? 'end'}
isOpen={side != null}
Closing clears that state, so `side` reverts to its default mid-exit and the
anchoring styles (`inset-inline-*`, the exit transform) flip under the panel.
Measured on the story: opened from `start`, the first frame of the close
already reads `left: 500px` and slides to +400px.
`side` is now latched at open and held for the exit, exactly as the children
are. Same rule as the documented "keep the last-selected item rendered on
close": what the panel shows while leaving is what it showed when open.
cixzhang
left a comment
There was a problem hiding this comment.
Thanks for chasing this down. The matched close frames show the fix:
| Before | Head |
|---|---|
![]() |
![]() |
Two things before merge. The close now coordinates render state, a transition listener, timer, flushSync, and unmount cleanup, but the tests mock the dialog in jsdom. A future change can restore the same post-close() frame for anyone using a transformed ancestor while all 37 tests stay green. Could you move the close timing into a named hook or utility and add that Chromium regression? BottomSheetPanel.waitForTransition is the closest existing pattern.
Please also add the start-side latch to the PR body: builders using the documented state-derived side shape now get a different exit and theme-state value, but that second change is not described.
[Reviewed by Robohands]
The close fix coordinated native dialog state, React-rendered presence, transition events, a computed-duration backstop, focus restoration and unmount cleanup inline in Drawer. Move that lifecycle into `useDrawerDialogPresence`, with `waitForDrawerExit` following the existing `BottomSheetPanel.waitForTransition` pattern: transitionend/transitioncancel are authoritative and a timeout only prevents a lost event from stranding an open dialog. Extend the existing real-browser `modal-close-visibility` CI guard with the Drawer invariant. It gives the Storybook root a transform (the actual failure condition), opens and closes the modal Drawer, then samples immediately before the next paint. The test fails if the closed dialog is still rendered outside the top layer. Negative control against origin/main: Drawer painted after close() at display:flex, open:false, x:624, width:374 Head: close() ran at display:flex; hidden before the next paint This closes the gap jsdom cannot cover: CSS transitions and the browser top layer do not exist there, so every unit test stays green when the bad frame is restored.
|
Addressed both asks in 0f5cf50.
Local gates: 37 Drawer tests, lab typecheck + docs typecheck, |
cixzhang
left a comment
There was a problem hiding this comment.
Thanks—both asks from my earlier review are addressed: the lifecycle is isolated with a passing Chromium regression, and the start-side behavior is now documented. Good to merge.
[Reviewed by Robohands]


The bug
Dismiss a
Drawerand the panel can snap back into the page for the tail of the close, over the content the user just dismissed it from.Two things combine:
dialog.close()ran on a hardcoded 250 ms timer with no relation to the panel's own transition.--duration-mediumis a theme token — 410 ms in the shipped defaults, 250 ms iny2k, 300 ms in the theme Storybook renders with — so the timer is either early (slide cut short) or racing the boundary.close(), held by the discretedisplaytransition.Once
close()releases the top layer, the panel is an ordinaryposition: fixedbox again — and any ancestor that establishes a containing block for fixed positioning (transform,filter,container-type,contain,backdrop-filter,will-change) becomes its origin. So the panel that had slid off the viewport edge reappears inside that ancestor and paints, shadow and all, until the hold ends.That is not exotic: Storybook's own docs page has such an ancestor, and so does any card, virtualised list, or view-transition wrapper.
Repro
Lab/Drawer→Showcase, with one line added to the story root:Open the drawer, close it, and watch the frames.
Before —
origin/main@ 58f9542:dialog.opendisplayThe panel is 291 px back inside the viewport, after the user dismissed it.
After — this branch:
dialog.opendisplayThe slide now finishes (x reaches 900) and the panel is already hidden by the time it leaves the top layer. The probe that catches the offending frame reports
never painted outside the top layer.Screenshots
The dashed box is the ancestor carrying the
transform. Drawer open:Before — the frame after
close(), with the drawer already dismissed. The panel is back inside the page:After — the same moment on this branch. There is no such frame; this is the first frame after
close():(Assets live on the
assets/pr-5549branch of this repo — asset-only, deletable with the PR. I have no fork.)The fix
transitionendfortransform, backstopped by the duration read off the element — so a theme that rewrites--duration-mediumis respected rather than assumed. Same contractBottomSheetPanel.waitForTransitionalready uses, and it replaces the reduced-motion special case for free (the CSS already collapses to0.01s).close(), viaflushSync. A plainsetStateis not enough — React's default scheduling can commit after the next paint, and that one frame is the bug. I measured this: with a plainsetStatethe offending frame was still there at x=600.displayfor both legs, so the discretedisplaytransition (andtransition-behavior: allow-discrete) is gone.@starting-stylestill drives the entry; it applies whenever an element goes from not-rendered to rendered and does not needdisplayin the transition.useDrawerDialogPresencenow owns native open/close,waitForDrawerExit, computed-duration backstop, synchronous hide, focus restoration, and unmount cleanup.waitForDrawerExitfollowsBottomSheetPanel.waitForTransition:transitionend/transitioncancelare authoritative and the timeout only prevents a lost event from stranding an open dialog.Start-side exit latch
This PR also fixes the
sideprop changing during the exit. The documented state-derived shape is:Closing clears
side, so the live prop reverted toendwhile the panel was still mounted for its exit. A drawer opened fromstarttherefore teleported to the end edge and slid out right; itsdata-sidetheme state changed mid-exit too. The side is now latched while open and held until the exit completes — the same retention contract the docs already require for the drawer's children. The regression test assertsdata-side="start"after the controlling state has cleared.Notes
.doc.mjschange.@astryxdesign/labis private, socheck:changesetsrejects a changeset for it — none added.onClose, which is not a prop, sopnpm -F @astryxdesign/lab typecheckwas already failing onmain. One word, and the file typechecks.Test plan
pnpm exec vitest run packages/lab/src/Drawer— 37 pass (34 before; closes ontransitionend, ignores atransitionendfor another property, and holds the opening side through exit; the existing delay test also asserts the drawer is still open at 250 ms).pnpm -F @astryxdesign/lab typecheck— clean (red onmain, see above).pnpm lint:strict— 0 errors.pnpm build,pnpm -F @astryxdesign/storybook build— green.close() ran at display:flex; hidden before the next paint. Negative control againstorigin/main:painted after close() outside the top layer — display:flex, open:false, x:624, width:374. The same guard keeps its existing MobileNav invariant green.