-
-
Notifications
You must be signed in to change notification settings - Fork 208
Closed
Description
When using conditional panels with layout persistence, the persisted layout for hidden panels gets overwritten on initial load. This worked correctly in v3 but regressed in v4.
v3 Code & Behavior (worked)
<PanelGroup
autoSaveId="my-layout"
direction="horizontal"
>
<Panel order={1} id="main" defaultSize={80}>Main</Panel>
<PanelResizeHandle />
{showSidebar && (
<>
<Panel order={2} defaultSize={20} id="sidebar">Sidebar</Panel>
</>
)}
</PanelGroup>v3 stored separate layouts per panel configuration:
{
"sidebar,main": {
"expandToSizes": {},
"layout": [63.31, 36.69]
},
"main": {
"expandToSizes": {},
"layout": [100]
}
}When panels changed, v3 looked up the layout for that specific combination of panel IDs. Hidden panels didn't affect persisted layouts for other configurations.
v4 Code & Behavior (broken)
const { defaultLayout, onLayoutChange } = useDefaultLayout({
id: 'my-layout',
storage: localStorage,
});
<Group defaultLayout={defaultLayout} onLayoutChange={onLayoutChange}>
<Panel id="main" defaultSize="80%">Main</Panel>
<Separator />
{showSidebar && (
<>
<Panel id="sidebar" defaultSize="20%">Sidebar</Panel>
</>
)}
</Group>- Layout stored as object:
{ main: 80, sidebar: 20 } - On initial render with only
mainvisible,onLayoutChangefires with{ main: 100 } storage.setItemoverwrites stored layout → sidebar's persisted size lost- When sidebar mounts, it falls back to
defaultSizeinstead of the persisted value
Reproduction Steps
- Load page with
showSidebar=true - Resize sidebar to 30%
- Reload page with
showSidebar=false(or sidebar conditionally hidden on initial render) - Toggle
showSidebar=true
Expected: Sidebar restores to 30%
Actual: Sidebar resets to defaultSize (20%)
Reproduction
https://codesandbox.io/p/sandbox/8hznkp
Environment
react-resizable-panels: 4.0.16- React: 19.2.3
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels