From f5291b7539ce8b5ca261eecaf991f6776e0fcd59 Mon Sep 17 00:00:00 2001 From: Mary Hipp Date: Wed, 20 Nov 2024 14:13:19 -0500 Subject: [PATCH 1/3] fix(ui): make sure schema has loaded before trying to load any workflows --- .../frontend/web/src/app/components/App.tsx | 4 +-- .../web/src/app/hooks/useStudioInitAction.ts | 28 +++++++++++-------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/invokeai/frontend/web/src/app/components/App.tsx b/invokeai/frontend/web/src/app/components/App.tsx index 2902c344adb..dcfb23388fc 100644 --- a/invokeai/frontend/web/src/app/components/App.tsx +++ b/invokeai/frontend/web/src/app/components/App.tsx @@ -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(); diff --git a/invokeai/frontend/web/src/app/hooks/useStudioInitAction.ts b/invokeai/frontend/web/src/app/hooks/useStudioInitAction.ts index a48311e5f28..f90dfaa592c 100644 --- a/invokeai/frontend/web/src/app/hooks/useStudioInitAction.ts +++ b/invokeai/frontend/web/src/app/hooks/useStudioInitAction.ts @@ -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, handleSelectStylePreset, handleGoToDestination]); + + useEffect(() => { + if (didInit.current || !action || !schemaLoaded) { + return; + } + + didInit.current = true; + + if (action.type === 'loadWorkflow') { + handleLoadWorkflow(action.data.workflowId); } - }, [ - handleSendToCanvas, - handleUseAllMetadata, - action, - handleLoadWorkflow, - handleSelectStylePreset, - handleGoToDestination, - ]); + }, [action, handleLoadWorkflow, schemaLoaded]); }; From 9acb4bc2aafbafab5477ba193157eafb86e19703 Mon Sep 17 00:00:00 2001 From: Mary Hipp Date: Wed, 20 Nov 2024 14:26:20 -0500 Subject: [PATCH 2/3] limit to one hook --- .../web/src/app/hooks/useStudioInitAction.ts | 39 ++++++++++++------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/invokeai/frontend/web/src/app/hooks/useStudioInitAction.ts b/invokeai/frontend/web/src/app/hooks/useStudioInitAction.ts index f90dfaa592c..77f11d54a01 100644 --- a/invokeai/frontend/web/src/app/hooks/useStudioInitAction.ts +++ b/invokeai/frontend/web/src/app/hooks/useStudioInitAction.ts @@ -178,35 +178,44 @@ export const useStudioInitAction = (action?: StudioInitAction, schemaLoaded?: bo return; } - didInit.current = true; - switch (action.type) { + case 'loadWorkflow': + if (schemaLoaded) { + handleLoadWorkflow(action.data.workflowId); + didInit.current = true; + } + break; + case 'selectStylePreset': handleSelectStylePreset(action.data.stylePresetId); + didInit.current = true; break; + case 'sendToCanvas': handleSendToCanvas(action.data.imageName); + didInit.current = true; break; + case 'useAllParameters': handleUseAllMetadata(action.data.imageName); + didInit.current = true; break; + case 'goToDestination': handleGoToDestination(action.data.destination); + didInit.current = true; break; + default: break; } - }, [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]); + }, [ + handleSendToCanvas, + handleUseAllMetadata, + action, + handleSelectStylePreset, + handleGoToDestination, + handleLoadWorkflow, + schemaLoaded, + ]); }; From 4ea91499fc4149a066815f9a77c2b20758ab3c4d Mon Sep 17 00:00:00 2001 From: Mary Hipp Date: Wed, 20 Nov 2024 15:02:13 -0500 Subject: [PATCH 3/3] use nanostore for schema parsed instead --- .../frontend/web/src/app/components/App.tsx | 4 ++-- .../web/src/app/hooks/useStudioInitAction.ts | 21 ++++++++----------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/invokeai/frontend/web/src/app/components/App.tsx b/invokeai/frontend/web/src/app/components/App.tsx index dcfb23388fc..2902c344adb 100644 --- a/invokeai/frontend/web/src/app/components/App.tsx +++ b/invokeai/frontend/web/src/app/components/App.tsx @@ -59,7 +59,7 @@ const App = ({ config = DEFAULT_CONFIG, studioInitAction }: Props) => { useSocketIO(); useGlobalModifiersInit(); useGlobalHotkeys(); - const { data: openApiData } = useGetOpenAPISchemaQuery(); + useGetOpenAPISchemaQuery(); useSyncLoggingConfig(); const handleReset = useCallback(() => { @@ -83,7 +83,7 @@ const App = ({ config = DEFAULT_CONFIG, studioInitAction }: Props) => { dispatch(appStarted()); }, [dispatch]); - useStudioInitAction(studioInitAction, !!openApiData); + useStudioInitAction(studioInitAction); useStarterModelsToast(); useSyncQueueStatus(); useFocusRegionWatcher(); diff --git a/invokeai/frontend/web/src/app/hooks/useStudioInitAction.ts b/invokeai/frontend/web/src/app/hooks/useStudioInitAction.ts index 77f11d54a01..64bfbb5bd7d 100644 --- a/invokeai/frontend/web/src/app/hooks/useStudioInitAction.ts +++ b/invokeai/frontend/web/src/app/hooks/useStudioInitAction.ts @@ -1,3 +1,4 @@ +import { useStore } from '@nanostores/react'; import { useAppStore } from 'app/store/storeHooks'; import { useAssertSingleton } from 'common/hooks/useAssertSingleton'; import { withResultAsync } from 'common/util/result'; @@ -9,6 +10,7 @@ import { imageDTOToImageObject } from 'features/controlLayers/store/util'; import { $imageViewer } from 'features/gallery/components/ImageViewer/useImageViewer'; import { sentImageToCanvas } from 'features/gallery/store/actions'; import { parseAndRecallAllMetadata } from 'features/metadata/util/handlers'; +import { $hasTemplates } from 'features/nodes/store/nodesSlice'; import { $isWorkflowListMenuIsOpen } from 'features/nodes/store/workflowListMenu'; import { $isStylePresetsMenuOpen, activeStylePresetIdChanged } from 'features/stylePresets/store/stylePresetSlice'; import { toast } from 'features/toast/toast'; @@ -46,11 +48,12 @@ export type StudioInitAction = * - Use `getImageDTO` helper instead of `useGetImageDTO` * - Usee the `$imageViewer` atom instead of `useImageViewer` */ -export const useStudioInitAction = (action?: StudioInitAction, schemaLoaded?: boolean) => { +export const useStudioInitAction = (action?: StudioInitAction) => { useAssertSingleton('useStudioInitAction'); const { t } = useTranslation(); // Use a ref to ensure that we only perform the action once const didInit = useRef(false); + const didParseOpenAPISchema = useStore($hasTemplates); const store = useAppStore(); const { getAndLoadWorkflow } = useGetAndLoadLibraryWorkflow(); @@ -174,36 +177,30 @@ export const useStudioInitAction = (action?: StudioInitAction, schemaLoaded?: bo ); useEffect(() => { - if (didInit.current || !action) { + if (didInit.current || !action || !didParseOpenAPISchema) { return; } + didInit.current = true; + switch (action.type) { case 'loadWorkflow': - if (schemaLoaded) { - handleLoadWorkflow(action.data.workflowId); - didInit.current = true; - } + handleLoadWorkflow(action.data.workflowId); break; - case 'selectStylePreset': handleSelectStylePreset(action.data.stylePresetId); - didInit.current = true; break; case 'sendToCanvas': handleSendToCanvas(action.data.imageName); - didInit.current = true; break; case 'useAllParameters': handleUseAllMetadata(action.data.imageName); - didInit.current = true; break; case 'goToDestination': handleGoToDestination(action.data.destination); - didInit.current = true; break; default: @@ -216,6 +213,6 @@ export const useStudioInitAction = (action?: StudioInitAction, schemaLoaded?: bo handleSelectStylePreset, handleGoToDestination, handleLoadWorkflow, - schemaLoaded, + didParseOpenAPISchema, ]); };