Fix for persistence on page reload

This commit is contained in:
Joey
2025-12-01 11:04:42 +00:00
parent 32764bf74e
commit ac188c1fe1
2 changed files with 16 additions and 3 deletions
@@ -30,6 +30,12 @@ export function useCanvasPersistence() {
// Save state to storage whenever it changes, including Explore state
useEffect(() => {
// Don't persist an empty canvas; this avoids removing a previously saved
// non-empty canvas when the in-memory state is still at its initial value.
if (!exploreMapState || Object.keys(exploreMapState.panels || {}).length === 0) {
return;
}
try {
// Enrich exploreMapState with current Explore state for each panel
const enrichedState: ExploreMapState = {
@@ -201,9 +201,16 @@ const exploreMapSlice = createSlice({
loadCanvas: (state, action: PayloadAction<ExploreMapState>) => {
const loadedState = action.payload;
// Clear any selection state from loaded data
loadedState.selectedPanelIds = [];
return loadedState;
// Merge with initial state to ensure we always have required defaults
// and to avoid persisting ephemeral state like selection and cursors.
return {
...initialExploreMapState,
...loadedState,
panels: loadedState.panels || {},
selectedPanelIds: [],
cursors: {},
};
},
updateCursor: (state, action: PayloadAction<UserCursor>) => {