From eadf5260c4eee64cd01f37a5ab50e9ff1a3b8da4 Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Thu, 7 Mar 2024 13:26:22 +0500 Subject: [PATCH] web: fix race condition where editor context would be destroyed and updated at the same time --- apps/web/src/components/editor/manager.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 { | ((oldState: EditorContext) => Partial) ) => { 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 }; }); };