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.

fix(webv2): memoize preview list ordering and cover inspector edges

joshistoast5364ac31f417
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/graph-preview/GraphPreviewDialog.browser.test.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/graph-preview/GraphPreviewDialog.browser.test.tsx
index 3873d4c370..b5c71f305e 100644
--- a/invokeai/frontend/webv2/src/features/workflow/ui/graph-preview/GraphPreviewDialog.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/features/workflow/ui/graph-preview/GraphPreviewDialog.browser.test.tsx
@@ -170,7 +170,7 @@ describe('GraphPreviewDialog', () => {
let onOpenChange: (isOpen: boolean) => void;
let graphPreviewPort: WorkflowGraphPreviewPort;
- const renderDialog = async (source: GraphPreviewSourceState) => {
+ const renderDialog = async (source: GraphPreviewSourceState, isOpen = true) => {
const workflowUiAdapter = createWorkflowUiAdapter();
await act(() => {
@@ -181,7 +181,7 @@ describe('GraphPreviewDialog', () => {
<WorkflowGraphPreviewProvider adapter={graphPreviewPort}>
<GraphPreviewDialog
graphId="preview-graph-id"
- isOpen
+ isOpen={isOpen}
source={source}
sourceId="generate"
sourceLabel="Generate"
@@ -290,6 +290,13 @@ describe('GraphPreviewDialog', () => {
expect(text).toContain('28');
expect(text).toContain('Set by');
expect(text).toContain('Generate → Steps');
+
+ // The fixture's `denoise_latents` node has one incoming edge (from `seed`)
+ // and one outgoing edge (to `l2i`) — exercise both `getEdgesInLine` and
+ // the per-edge `edgesOut` lines, not just that the "Edges" heading renders.
+ expect(text).toContain('Edges');
+ expect(text).toContain('in · 1 inputs from seed');
+ expect(text).toContain('out · latents → l2i');
});
it('show node selects the seed node and inspector shows the randomized override', async () => {
@@ -313,4 +320,26 @@ describe('GraphPreviewDialog', () => {
expect(graphPreviewPort.focusSource).toHaveBeenCalledWith('generate');
expect(onOpenChange).toHaveBeenCalledWith(false);
});
+
+ it('clears the selected node when the dialog closes and reopens', async () => {
+ await renderDialog(FIXTURE_SOURCE);
+
+ await switchToMode('list');
+ await clickButtonWithText('denoise_latents');
+ expect(document.body.textContent ?? '').toContain('Resolved inputs');
+
+ // The footer Close button is the path `closeAndReset` resets `selectedNodeId`
+ // through. Re-render with `isOpen` false then true to simulate the parent
+ // obeying the `onOpenChange(false)` this just triggered and reopening —
+ // the same controlled-`open` round trip a real host does.
+ await clickButtonWithText('Close');
+ expect(onOpenChange).toHaveBeenCalledWith(false);
+
+ await renderDialog(FIXTURE_SOURCE, false);
+ await renderDialog(FIXTURE_SOURCE, true);
+
+ const text = document.body.textContent ?? '';
+ expect(text).toContain('Select a node for details.');
+ expect(text).not.toContain('Resolved inputs');
+ });
});
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/graph-preview/GraphPreviewList.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/graph-preview/GraphPreviewList.tsx
index 8882f7d6fb..166a8f04de 100644
--- a/invokeai/frontend/webv2/src/features/workflow/ui/graph-preview/GraphPreviewList.tsx
+++ b/invokeai/frontend/webv2/src/features/workflow/ui/graph-preview/GraphPreviewList.tsx
@@ -2,7 +2,7 @@ import type { WorkflowPreviewGraph } from '@features/workflow/ui/contracts';
import { Badge, Button, Stack, Text } from '@chakra-ui/react';
import { getTopologicalOrder } from '@features/workflow/core/graphLayout';
-import { useCallback } from 'react';
+import { useCallback, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { getNodeSubtitle } from './nodeSummaries';
@@ -55,19 +55,24 @@ export const GraphPreviewList = ({
graph: WorkflowPreviewGraph;
onSelect: (nodeId: string) => void;
}) => {
- const nodesById = new Map(graph.nodes.map((node) => [node.id, node]));
- const order = getTopologicalOrder(
- graph.nodes,
- graph.edges.map((edge) => ({ sourceNodeId: edge.sourceNodeId, targetNodeId: edge.targetNodeId }))
- );
+ // Live sources (e.g. Generate) recompile on every keystroke — re-sorting and
+ // re-mapping the node list on every one of those renders (not just when the
+ // graph itself changes) would make leaving List mode open needlessly costly.
+ const orderedNodes = useMemo(() => {
+ const nodesById = new Map(graph.nodes.map((node) => [node.id, node]));
+ const order = getTopologicalOrder(
+ graph.nodes,
+ graph.edges.map((edge) => ({ sourceNodeId: edge.sourceNodeId, targetNodeId: edge.targetNodeId }))
+ );
+
+ return order.map((nodeId) => nodesById.get(nodeId)).filter((node): node is PreviewListNode => node !== undefined);
+ }, [graph]);
return (
<Stack gap="1" h="full" overflowY="auto" p="2">
- {order.map((nodeId) => {
- const node = nodesById.get(nodeId);
-
- return node ? <GraphPreviewListRow key={node.id} node={node} onSelect={onSelect} /> : null;
- })}
+ {orderedNodes.map((node) => (
+ <GraphPreviewListRow key={node.id} node={node} onSelect={onSelect} />
+ ))}
</Stack>
);
};