fix(ui): make sure schema has loaded before trying to load any workflows

This commit is contained in:
Mary Hipp
2024-11-20 14:13:19 -05:00
committed by Mary Hipp Rogers
parent 549f4e9794
commit 0d86de0cb5
2 changed files with 18 additions and 14 deletions

View File

@@ -59,7 +59,7 @@ const App = ({ config = DEFAULT_CONFIG, studioInitAction }: Props) => {
useSocketIO();
useGlobalModifiersInit();
useGlobalHotkeys();
useGetOpenAPISchemaQuery();
const { data: openApiData } = useGetOpenAPISchemaQuery();
useSyncLoggingConfig();
const handleReset = useCallback(() => {
@@ -83,7 +83,7 @@ const App = ({ config = DEFAULT_CONFIG, studioInitAction }: Props) => {
dispatch(appStarted());
}, [dispatch]);
useStudioInitAction(studioInitAction);
useStudioInitAction(studioInitAction, !!openApiData);
useStarterModelsToast();
useSyncQueueStatus();
useFocusRegionWatcher();

View File

@@ -46,7 +46,7 @@ export type StudioInitAction =
* - Use `getImageDTO` helper instead of `useGetImageDTO`
* - Usee the `$imageViewer` atom instead of `useImageViewer`
*/
export const useStudioInitAction = (action?: StudioInitAction) => {
export const useStudioInitAction = (action?: StudioInitAction, schemaLoaded?: boolean) => {
useAssertSingleton('useStudioInitAction');
const { t } = useTranslation();
// Use a ref to ensure that we only perform the action once
@@ -181,9 +181,6 @@ export const useStudioInitAction = (action?: StudioInitAction) => {
didInit.current = true;
switch (action.type) {
case 'loadWorkflow':
handleLoadWorkflow(action.data.workflowId);
break;
case 'selectStylePreset':
handleSelectStylePreset(action.data.stylePresetId);
break;
@@ -196,13 +193,20 @@ export const useStudioInitAction = (action?: StudioInitAction) => {
case 'goToDestination':
handleGoToDestination(action.data.destination);
break;
default:
break;
}
}, [
handleSendToCanvas,
handleUseAllMetadata,
action,
handleLoadWorkflow,
handleSelectStylePreset,
handleGoToDestination,
]);
}, [handleSendToCanvas, handleUseAllMetadata, action, handleSelectStylePreset, handleGoToDestination]);
useEffect(() => {
if (didInit.current || !action || !schemaLoaded) {
return;
}
didInit.current = true;
if (action.type === 'loadWorkflow') {
handleLoadWorkflow(action.data.workflowId);
}
}, [action, handleLoadWorkflow, schemaLoaded]);
};