Persistence
Save and restore layout state across sessions.
The layout tree is plain serializable JSON, so saving and restoring a user's workspace is straightforward. No special serialization logic is required — JSON.stringify and JSON.parse are all you need.
Basic localStorage pattern
onChange fires after every mutation (resize, tab switch, split, collapse, etc.) with the new layout tree. Write it wherever you like — localStorage, a database, URL state, etc.
What is saved
Everything in the layout tree is saved:
- Panel positions and split structure
- Tab lists per panel (order, ids, titles, tabType, meta)
- Active tab per panel
- Panel sizes (as percentages)
- Collapsed state per panel
What is not saved: the content inside tabs. The registry's render function is called fresh on restore — the tab descriptor (including meta) is what reconnects a tab to its content.
Saving to a database
For frequent mutations (resize drags), debounce the onChange callback to avoid flooding the server:
Resetting or switching layouts at runtime
To swap the entire layout without remounting the provider, dispatch REPLACE_LAYOUT:
To reset to the default layout, dispatch with the default:
Important: initialLayout is a snapshot
LayoutProvider reads initialLayout once on mount. Changing the prop after mount does nothing — the store is the source of truth from that point. To reset externally, either dispatch REPLACE_LAYOUT or remount with a new key:
Schema versioning
If you evolve the layout tree structure across app versions, store a schema version alongside the layout and migrate on load: