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

This commit is contained in:
Abdullah Atta
2024-03-07 13:26:22 +05:00
parent 2d9f41e114
commit 3a2eba3242

View File

@@ -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 };
});
};