bvaughn / react-resizable-panels

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

Panel and PanelGroup imperative APIs don't work well on mount #217

Closed bvaughn closed 10 months ago

bvaughn commented 10 months ago

Related to #211

PanelGroup can't provide a meaningful layout for Panels during the initial render because it doesn't yet know about their constraints. Panels register constraints with the parent PanelGroup on mount, which schedules an update so that PanelGroup can re-render them.

If a parent component uses Panel or PanelGroup imperative APIs on mount (before the scheduled update) the values returned won't be meaningful, and in some cases can even error.

I think the way to work around this is to move layout calculation from an effect to the registerPanel method and to eagerly calculate layouts once all panels have registered.