Skip to content

Commit ce47e31

Browse files
authored
Move cell delete ops inside setState callback to prevent race condition (#5813)
State was being cleared before delete operations completed. Moving deletes inside setState ensures proper sequencing. We should probably refactor to reducer pattern to remove React state from business logic.
1 parent cb3c1e9 commit ce47e31

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

frontend/src/core/cells/pending-delete-service.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,14 @@ export function usePendingDelete(cellId: CellId) {
111111
}
112112
const entries = [...state.values()];
113113
if (entries.every((entry) => entry.type === "simple")) {
114-
if (state.size === 1) {
115-
deleteCell({ cellId: entries[0].cellId });
116-
} else {
117-
deleteManyCells({ cellIds: entries.map((e) => e.cellId) });
118-
}
119-
setState(new Map());
114+
setState(() => {
115+
if (state.size === 1) {
116+
deleteCell({ cellId: entries[0].cellId });
117+
} else {
118+
deleteManyCells({ cellIds: entries.map((e) => e.cellId) });
119+
}
120+
return new Map();
121+
});
120122
}
121123
}, [state, deleteCell, deleteManyCells, setState]);
122124

0 commit comments

Comments
 (0)