Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

Move cell delete ops inside `setState` callback to prevent race condition (#5813)

Trevor Manzce47e31dd1fc
diff --git a/frontend/src/core/cells/pending-delete-service.ts b/frontend/src/core/cells/pending-delete-service.ts
index 8d187a9511..a7c1965a0f 100644
--- a/frontend/src/core/cells/pending-delete-service.ts
+++ b/frontend/src/core/cells/pending-delete-service.ts
@@ -111,12 +111,14 @@ export function usePendingDelete(cellId: CellId) {
}
const entries = [...state.values()];
if (entries.every((entry) => entry.type === "simple")) {
- if (state.size === 1) {
- deleteCell({ cellId: entries[0].cellId });
- } else {
- deleteManyCells({ cellIds: entries.map((e) => e.cellId) });
- }
- setState(new Map());
+ setState(() => {
+ if (state.size === 1) {
+ deleteCell({ cellId: entries[0].cellId });
+ } else {
+ deleteManyCells({ cellIds: entries.map((e) => e.cellId) });
+ }
+ return new Map();
+ });
}
}, [state, deleteCell, deleteManyCells, setState]);