From 9f964c0937adca8fd1a527001fe8e9fe3034f618 Mon Sep 17 00:00:00 2001 From: Liz Looney Date: Wed, 12 Nov 2025 22:59:59 -0800 Subject: [PATCH] Modified Tabs so it waits for the saveModule to finish before switching tabs. Modified TabContent so when a module is saved, it updates modulePathToContentText. --- src/reactComponents/TabContent.tsx | 6 +++++- src/reactComponents/Tabs.tsx | 10 ++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/reactComponents/TabContent.tsx b/src/reactComponents/TabContent.tsx index 8c665e6f..296cebae 100644 --- a/src/reactComponents/TabContent.tsx +++ b/src/reactComponents/TabContent.tsx @@ -86,7 +86,11 @@ export const TabContent = React.forwardRef(({ React.useImperativeHandle(ref, () => ({ saveModule: async () => { if (editorInstance) { - await editorInstance.saveModule(); + const moduleContentText = await editorInstance.saveModule(); + // Update modulePathToContentText. + // modulePathToContentText is passed to Editor.makeCurrent so the active editor will know + // about changes to other modules. + modulePathToContentText[modulePath] = moduleContentText; } }, }), [editorInstance]); diff --git a/src/reactComponents/Tabs.tsx b/src/reactComponents/Tabs.tsx index 7adfce1b..ce3600fb 100644 --- a/src/reactComponents/Tabs.tsx +++ b/src/reactComponents/Tabs.tsx @@ -84,15 +84,17 @@ export function Component(props: TabsProps): React.JSX.Element { const tabContentRefs = React.useRef>(new Map()); /** Handles tab change and updates current module. */ - const handleTabChange = (key: string): void => { + const handleTabChange = async (key: string): Promise => { if (key !== activeKey) { - // Save the tab we are changing away from (async, but don't wait) + // Save the tab we are changing away from. Wait for the save to complete before changing tabs. const currentTabRef = tabContentRefs.current.get(activeKey); if (currentTabRef) { - currentTabRef.saveModule().catch((error) => { + try { + await currentTabRef.saveModule(); + } catch(error) { console.error('Error saving module on tab switch:', error); props.setAlertErrorMessage(t('FAILED_TO_SAVE_MODULE')); - }); + } } } setActiveKey(key);