[Accordion][Collapsible] Simplify shouldRender condition in AccordionPanel and CollapsiblePanel#4338
Conversation
Simplify shouldRender condition in AccordionPanel and CollapsiblePanel
There was a problem hiding this comment.
Pull request overview
This PR simplifies the render gating logic for AccordionPanel and CollapsiblePanel by removing a redundant !keepMounted check while keeping the same behavior for when panels should stay mounted or be rendered.
Changes:
- Simplified
shouldRenderinCollapsiblePaneltokeepMounted || hiddenUntilFound || mounted. - Simplified
shouldRenderinAccordionPaneltokeepMounted || hiddenUntilFound || mounted.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/react/src/collapsible/panel/CollapsiblePanel.tsx | Removes redundant boolean logic in the shouldRender condition without changing behavior. |
| packages/react/src/accordion/panel/AccordionPanel.tsx | Mirrors the same simplification for accordion panels to keep the logic consistent. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
commit: |
| }); | ||
|
|
||
| const shouldRender = keepMounted || hiddenUntilFound || (!keepMounted && mounted); | ||
| const shouldRender = keepMounted || hiddenUntilFound || mounted; |
There was a problem hiding this comment.
When shouldRender is evaluated, if keepMounted were true, the expression would already short-circuit. So !keepMounted is always true by the time the third operand is reached, making it redundant.
Bundle size report
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. |
Simplify shouldRender condition in AccordionPanel and CollapsiblePanel