From 2aeb875fecabcbaeb78374d8569428d17e4b74b6 Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Sat, 27 Jul 2024 10:00:10 +0500 Subject: [PATCH] web: fix crash on moving temporary tab --- apps/web/src/components/editor/action-bar.tsx | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/apps/web/src/components/editor/action-bar.tsx b/apps/web/src/components/editor/action-bar.tsx index 17dc64b01..7c31cbbac 100644 --- a/apps/web/src/components/editor/action-bar.tsx +++ b/apps/web/src/components/editor/action-bar.tsx @@ -281,21 +281,21 @@ function TabStrip() { items={sessions} moveItem={(from, to) => { if (from === to) return; - useEditorStore.setState((state) => { - const isToPinned = state.sessions[to].pinned; - const [fromTab] = state.sessions.splice(from, 1); + const sessions = useEditorStore.getState().sessions.slice(); + const isToPinned = sessions[to].pinned; + const [fromTab] = sessions.splice(from, 1); - // if the tab where this tab is being dropped is pinned, - // let's pin our tab too. - if (isToPinned) { - fromTab.pinned = true; - fromTab.preview = false; - } - // unpin the tab if it is moved. - else if (fromTab.pinned) fromTab.pinned = false; + // if the tab where this tab is being dropped is pinned, + // let's pin our tab too. + if (isToPinned) { + fromTab.pinned = true; + fromTab.preview = false; + } + // unpin the tab if it is moved. + else if (fromTab.pinned) fromTab.pinned = false; - state.sessions.splice(to, 0, fromTab); - }); + sessions.splice(to, 0, fromTab); + useEditorStore.setState({ sessions }); }} renderItem={({ item: session, index: i }) => (