Repository navigation
[popups] Keep transition state consistent when reopening a retained popup - #5738
Conversation
commit: |
Bundle size
PerformanceTotal duration: 1,224.72 ms -123.87 ms(-9.2%) | Renders: 76 (+0) | Paint: 1,997.33 ms -209.23 ms(-9.5%)
12 tests within noise — details Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
`open` reaches the popup store synchronously, while `mounted` and `transitionStatus` sync in a layout effect. A retained popup therefore renders one commit as open but not yet starting, so a transition driven by `open && transitionStatus !== 'starting'` enters twice, and completion can fire before the enter animation finishes. Derive the starting status in `popupStoreSelectors` instead of `MenuStore`. The defect is in the shared ordering, so this fixes Menu, Popover, Dialog, Tooltip and Preview Card together. Select and Combobox keep their own selectors and do not have the defect. Add unit coverage for the selector and a Popover browser regression. Co-Authored-By: Claude Opus 5 <[email protected]>
`waitFor` on a running 200ms transition needed a poll to land inside that window. Once it closed, `getAnimations()` stayed empty and the wait failed at timeout instead of retrying. Use a transition that outlasts every phase, then finish the animations to end the phase. This also removes the `pause()` workaround for the reversed exit. Stop asserting inside the `onOpenChangeComplete` mock. The library calls it from `flushSync` inside a promise continuation, so a throw escaped as an unhandled rejection rather than failing the test, and the check was vacuous on close. The test body already asserts the same thing. Co-Authored-By: Claude Opus 5 <[email protected]>
There was a problem hiding this comment.
🟢 Approval recommended
The focused selector correction matches the lifecycle behavior and is comprehensively covered by unit and browser regressions.
Pull request overview
Keeps popup transition state consistent when reopening retained popups.
Changes:
- Derives
startingwhile an open popup lifecycle is not mounted. - Adds selector unit tests and browser regressions for Menu and Popover.
File summaries
| File | Description |
|---|---|
packages/react/src/utils/popups/store.ts |
Corrects the shared transition selector. |
packages/react/src/utils/popups/store.test.ts |
Covers selector lifecycle states. |
packages/react/src/popover/popup/PopoverPopupTransitionState.test.tsx |
Tests retained Popover reopen cycles. |
packages/react/src/menu/popup/MenuPopupTransitionState.test.tsx |
Tests Menu lifecycle combinations and exit reversal. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 0
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Nit (non-blocking): simplify the two new browser test files. In This keeps all nine cases, including the Menu controlled/uncontrolled, 🤖 Review generated with Codex |
PR reviewOne non-blocking regression. Bugs (1)🟠 Initial-open Backdrops can incorrectly get
|
Noticed while working on mui/material-ui#48823.
When a retained popup reopens,
openreaches the store beforemountedandtransitionStatussynchronize in a layout effect. A transition driven byopen && transitionStatus !== 'starting'can then enter twice, andonOpenChangeCompletecan fire before entry finishes.Derive
startingfrom the effective open state while the lifecycle is not mounted. The shared selector covers Menu, Popover, Dialog, Tooltip, and Preview Card. Select and Combobox use separate selectors and synchronize these lifecycle values in one store update.Also initialize the store's
mountedvalue fromuseTransitionStatusbefore child parts render. This makes the initial store state agree with the hook: an ordinary initially-open Root is already mounted and does not expose a spuriousstartingstate to a direct-Root Backdrop. Intentional initial submenu transitions still start normally. This initialization runs once; later openings, exit reversals, and completion tracking keep their existing lifecycle.Tests
starting, with controlled and uncontrolled state. These check public state consistency.The browser tests assert the committed state sequence and real animation-completion timing. They finish long-running animations explicitly; the Menu reversal case waits for
data-openbefore finishing the animation so the exit cannot finish before the reopen handler runs. Redundant syntheticonEntertracking and repeated cycles outside the original initially-open retained Menu scenario have been removed.Validation
Local validation after merging
master(53e533a48) inf3519722a, using React 19.3.0:222 committed Backdrop and transition cases pass across Chromium, Firefox, and WebKit, including the existing submenu enter-transition suite.
Related Chromium suites: 3,083 passed, 67 skipped.
Related jsdom suites: 2,332 passed, 818 skipped.
TypeScript, ESLint, stylelint, Prettier, and diff whitespace checks pass.
Earlier regression checks: removing the selector fix fails the same 15 retained-popup cases across the three browsers. Before the initialization correction, the new Menu and controlled Popover Backdrop assertions fail on the unexpected
startingstate. A temporary six-component Backdrop probe passes all 36 initial-open cases with the correction.I have followed the PR section of the contributing guide.