Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

web: fix race condition where editor context would be destroyed and updated at the same time

Abdullah Atta3a2eba32429b
diff --git a/apps/web/src/components/editor/manager.ts b/apps/web/src/components/editor/manager.ts
index 0c8d6ef71..c425dfb51 100644
--- a/apps/web/src/components/editor/manager.ts
+++ b/apps/web/src/components/editor/manager.ts
@@ -61,9 +61,11 @@ class EditorManager extends BaseStore<EditorManager> {
| ((oldState: EditorContext) => Partial<EditorContext>)
) => {
this.set((state) => {
+ const oldState = state.editors[id];
+ if (!oldState) return;
const newPartialState =
- typeof partial === "function" ? partial(state.editors[id]) : partial;
- state.editors[id] = { ...state.editors[id], ...newPartialState };
+ typeof partial === "function" ? partial(oldState) : partial;
+ state.editors[id] = { ...oldState, ...newPartialState };
});
};