bvaughn / react-resizable-panels

https://react-resizable-panels.vercel.app/
MIT License
3.87k stars 135 forks source link

Assertion Failed on conditionally rendered panels with size constraints #303

Closed DenizUgur closed 7 months ago

DenizUgur commented 7 months ago

Hi @bvaughn, first of all thank you for this amazing library. It has been a core feature for my project. In my project, I'm using resizable panels dynamically. As in, there are a set of layouts with size constraints defined in them as well. When I switch between layouts I get an assertion error. I've found out this is due to minSize and maxSize being supplied. Most probably I'm not using them as they should so I would love it if you could shine a light on this.

Here is a repro: https://codesandbox.io/p/sandbox/youthful-jennings-wt9ffk

bvaughn commented 7 months ago

Thanks for the repro. I will try to take a look sometime soon.

DenizUgur commented 7 months ago

Okay found the problem, my outermost panel group had the same id despite the layout's change. Replacing it with unique ID or crypto.randomUUID() solved the problem.

key must also be unique

Possibly a check for duplicate id's across re-render could be implemented?

bvaughn commented 7 months ago

That's interesting. Even with the same id, layouts should be stored uniquely based on the group id and the combination of panel constraints (so if you conditionally rendered panels, they don't clobber each others layouts).

Would you be able to reduce your repro to a failing unit test (in this repo)? That would help me fix it.

DenizUgur commented 7 months ago

Let me try to do that. I'll try open a PR today

bvaughn commented 7 months ago

Thank you! That would be super helpful.

DenizUgur commented 7 months ago

Solution was found in the PR

bvaughn commented 7 months ago

Fix published in 2.0.10