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
main visible, onLayoutChange fires with { main: 100 }
storage.setItem overwrites stored layout → sidebar's persisted size lost
- When sidebar mounts, it falls back to
defaultSize instead 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
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)
v3 stored separate layouts per panel configuration:
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)
{ main: 80, sidebar: 20 }mainvisible,onLayoutChangefires with{ main: 100 }storage.setItemoverwrites stored layout → sidebar's persisted size lostdefaultSizeinstead of the persisted valueReproduction Steps
showSidebar=trueshowSidebar=false(or sidebar conditionally hidden on initial render)showSidebar=trueExpected: Sidebar restores to 30%
Actual: Sidebar resets to
defaultSize(20%)Reproduction
https://codesandbox.io/p/sandbox/8hznkp
Environment
react-resizable-panels: 4.0.16