Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

perf(webv2): defer workflow graph preview

joshistoastc7c0b589dc1d
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/graph-preview/GraphPreviewPane.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/graph-preview/GraphPreviewPane.tsx
new file mode 100644
index 0000000000..bdbea8fbff
--- /dev/null
+++ b/invokeai/frontend/webv2/src/features/workflow/ui/graph-preview/GraphPreviewPane.tsx
@@ -0,0 +1,25 @@
+import type { WorkflowPreviewState } from '@features/workflow/ui/library/WorkflowLibraryDialog';
+
+import { Box } from '@chakra-ui/react';
+import { useTranslation } from 'react-i18next';
+
+import { documentToPreviewGraph, GraphPreviewFlow } from './GraphPreviewFlow';
+
+/**
+ * The library dialog's node preview, conversion included.
+ *
+ * Both halves live here so the dialog can hold the whole thing behind one
+ * `lazy()` boundary: `documentToPreviewGraph` shares a module with the flow
+ * renderer, so importing it for the conversion alone pulled xyflow and d3
+ * (~174 KB) into every editor boot through the workflow widget's host.
+ */
+export const GraphPreviewPane = ({ document }: { document: WorkflowPreviewState['document'] }) => {
+ const { t } = useTranslation();
+ const { graph, positionHints } = documentToPreviewGraph(document, t('widgets.labels.workflow'));
+
+ return (
+ <Box h="24rem">
+ <GraphPreviewFlow graph={graph} positionHints={positionHints} />
+ </Box>
+ );
+};
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/graph-preview/index.ts b/invokeai/frontend/webv2/src/features/workflow/ui/graph-preview/index.ts
index 0c178971ff..f374e334b3 100644
--- a/invokeai/frontend/webv2/src/features/workflow/ui/graph-preview/index.ts
+++ b/invokeai/frontend/webv2/src/features/workflow/ui/graph-preview/index.ts
@@ -2,3 +2,4 @@ export { FlowMiniMap } from './FlowMiniMap';
export { flowThemeCss, getFlowColorMode } from './flowTheme';
export { GraphPreviewDialog } from './GraphPreviewDialog';
export { documentToPreviewGraph, GraphPreviewFlow } from './GraphPreviewFlow';
+export { GraphPreviewPane } from './GraphPreviewPane';
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryDialog.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryDialog.tsx
index d8fc858425..093302d0e7 100644
--- a/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryDialog.tsx
+++ b/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryDialog.tsx
@@ -12,7 +12,6 @@ import {
type WorkflowLibraryCategory,
type WorkflowLibraryListItem,
} from '@features/workflow/queries';
-import { documentToPreviewGraph, GraphPreviewFlow } from '@features/workflow/ui/graph-preview';
import { useProjectGraphCommands } from '@features/workflow/ui/useProjectGraphCommands';
import { useWorkflowNotifications, useWorkflowProjectSelector } from '@features/workflow/ui/WorkflowUiContext';
import { parseWorkflowJson, serializeWorkflowJson } from '@features/workflow/utility';
@@ -25,7 +24,7 @@ import {
import { getApiErrorMessage } from '@platform/transport/http';
import { Button, CloseButton, ConfirmDialog, JsonPreview, Scrollable } from '@platform/ui';
import { MiddleTruncate } from '@platform/ui/MiddleTruncate';
-import { useCallback, useEffect, useRef, useState, type ChangeEvent } from 'react';
+import { lazy, Suspense, useCallback, useEffect, useRef, useState, type ChangeEvent } from 'react';
import { useTranslation } from 'react-i18next';
import { markLibraryGraphSynced } from './librarySyncBridge';
@@ -39,7 +38,7 @@ import { useSaveWorkflowToLibrary } from './useSaveWorkflowToLibrary';
* cache instantly and revalidate in the background.
*/
-interface WorkflowPreviewState {
+export interface WorkflowPreviewState {
document: ProjectGraphState;
item: WorkflowLibraryListItem;
raw: Record<string, unknown>;
@@ -48,6 +47,12 @@ interface WorkflowPreviewState {
type WorkflowLoadPhase = 'fetching' | 'applying';
+const GraphPreviewPane = lazy(() =>
+ import('@features/workflow/ui/graph-preview/GraphPreviewPane').then((module) => ({
+ default: module.GraphPreviewPane,
+ }))
+);
+
const WorkflowPreviewPane = ({
isLoadingWorkflow,
preview,
@@ -60,8 +65,6 @@ const WorkflowPreviewPane = ({
onLoad: () => void;
}) => {
const [mode, setMode] = useState<'nodes' | 'json'>('nodes');
- const { t } = useTranslation();
- const { graph, positionHints } = documentToPreviewGraph(preview.document, t('widgets.labels.workflow'));
return (
<Stack gap="2">
@@ -92,9 +95,9 @@ const WorkflowPreviewPane = ({
</HStack>
</HStack>
{mode === 'nodes' ? (
- <Box h="24rem">
- <GraphPreviewFlow graph={graph} positionHints={positionHints} />
- </Box>
+ <Suspense fallback={<Box h="24rem" />}>
+ <GraphPreviewPane document={preview.document} />
+ </Suspense>
) : (
<JsonPreview label={`${preview.item.name} JSON`} maxH="24rem" value={preview.raw} />
)}