Skip to content

[collapsible] Finish closing when the render function removes the panel - #5890

Merged
michaldudak merged 1 commit into
mui:masterfrom
michaldudak:claude/fix-collapsible-removed-panel-close
Oct 6, 2026
Merged

michaldudak merged 1 commit into
mui:masterfrom
michaldudak:claude/fix-collapsible-removed-panel-close

Conversation

@michaldudak

Copy link
Copy Markdown
Member

If Collapsible.Panel's render function returns null once the panel closes, the close never finishes. The trigger keeps data-ending-style indefinitely, and mounted stays true.

The ending-phase effect in useCollapsiblePanel waits for the panel's close animations and then unmounts. When panelRef.current is null it returned early, so nothing ever called setMounted(false). With no element left to animate, it now finishes the close right away.

The guard sits in the ending-phase effect, not the earlier layout effect. A panel that is absent right after close but mounts again during the ending phase still animates out normally, as covered by "unmounts a panel that mounts after the close has already entered the ending phase".

Accordion uses the same hook, so its panels get the same fix.

Why the existing test didn't catch it

"supports removing the rendered panel as it closes" only asserted things that hold by construction (aria-expanded, the content being gone, onOpenChange(false)). In practice it only guarded against a crash on the null panel ref. It now also asserts that the trigger has no data-ending-style after closing, and is renamed to "finishes closing when the render function removes the panel element".

Validation

  • The updated test fails without the source change and passes with it.
  • Collapsible and Accordion suites pass in jsdom and Chromium. ESLint and Prettier pass.

Found during an audit of the test suite for tests that can't fail.

If Collapsible.Panel's render function drops the element as soon as the panel
closes, the ending-phase effect found no panel and returned without unmounting,
so the transition never completed and the trigger kept data-ending-style.

With no element left to animate, finish the close immediately.
@michaldudak michaldudak added type: bug It doesn't behave as expected. component: collapsible Changes related to the collapsible component. labels Oct 5, 2026
@pkg-pr-new

pkg-pr-new Bot commented Oct 5, 2026

Copy link
Copy Markdown
  • base-ui-tanstack-start

  • vite-css-base-ui-example

    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/react@5890
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@5890
    

commit: 70a7827

@code-infra-dashboard

code-infra-dashboard Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+25B(0.00%) 🔺+6B(0.00%)

Details of bundle changes

Performance

Total duration: 513.78 ms -12.56 ms(-2.4%) | Renders: 76 (+0) | Paint: 921.20 ms -33.49 ms(-3.5%)

Test Duration Renders
Scroll Area mount (300 instances) 47.80 ms +7.52 ms(+18.7%) 3 (+0)

14 tests within noise — details

Metric alarms

Test Metric Change
Scroll Area mount (300 instances) bench:paint 🔺 +11.16 ms

Check out the code infra dashboard for more information about this PR.

@netlify

netlify Bot commented Oct 5, 2026

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 70a7827
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6ac3a675375625000819f1db
😎 Deploy Preview https://deploy-preview-5890--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@michaldudak
michaldudak marked this pull request as ready for review October 5, 2026 13:46
@michaldudak
michaldudak merged commit 810c458 into mui:master Oct 6, 2026
25 checks passed
@michaldudak
michaldudak deleted the claude/fix-collapsible-removed-panel-close branch October 6, 2026 10:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: collapsible Changes related to the collapsible component. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant