Fix for persistence on page reload
This commit is contained in:
@@ -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>) => {
|
||||
|
||||
Reference in New Issue
Block a user