Skip to content

fix: edge case collapse last panel#703

Open
hugs7 wants to merge 7 commits intobvaughn:mainfrom
hugs7:bugfix/collapse-last-panel
Open

fix: edge case collapse last panel#703
hugs7 wants to merge 7 commits intobvaughn:mainfrom
hugs7:bugfix/collapse-last-panel

Conversation

@hugs7
Copy link
Copy Markdown

@hugs7 hugs7 commented Apr 6, 2026

When collapsing the a panel within a group where all other (previous) panels are already collapsed, there's currently a bug where the delta calculation cascades to cause the first panel to expand. This is undesired since the first panel should remain collapsed given we are not touching it.

This fix handles the edge case by computing the remaining space percentage for the last panel to take up, thus leaving previous panels undisturbed.

By "previous" panels here I mean panels above (vertical mode) or to the left (horizontal) mode.

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 6, 2026

@hugs7 is attempting to deploy a commit to the Brian Vaughn's projects Team on Vercel.

A member of the Team first needs to authorize it.

@hugs7
Copy link
Copy Markdown
Author

hugs7 commented Apr 6, 2026

Hi @bvaughn , could you kindly have a look at my PR?

const allPreviousCollapsed =
isLastPanel &&
nextSize < prevSize &&
(isFirstPanel ||
Copy link
Copy Markdown
Author

@hugs7 hugs7 Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also noticed this assertion error can happen when collapsing the one and only panel in a group, since the delta value otherwise goes to 100 causing it to index at -1 here at adjustLayoutByDelta on line 142

Image

Copy link
Copy Markdown
Author

@hugs7 hugs7 Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've addressed this in this PR via the following logic: If there's only one panel in the group, we can still collapse it but leave it's flex-grow value at 100%

@hugs7
Copy link
Copy Markdown
Author

hugs7 commented Apr 6, 2026

Unit tests

image

@bvaughn
Copy link
Copy Markdown
Owner

bvaughn commented Apr 6, 2026 via email

@hugs7
Copy link
Copy Markdown
Author

hugs7 commented Apr 6, 2026

No rush. Please take your time to review

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 10, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
react-resizable-panels Ready Ready Preview Apr 10, 2026 10:20pm

@bvaughn
Copy link
Copy Markdown
Owner

bvaughn commented Apr 10, 2026

Have not reviewed the code yet. TBH I'm still probably too exhausted to do this, BUT– I would like to see at least two new unit tests to be included w/ this sort of PR (for the edge cases you mention)

If you're willing to add them, I'd appreciate it!

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.

2 participants