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.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
fix(workflow): restore linear view switching
joshistoast4c5c5ff2f415
diff --git a/invokeai/frontend/webv2/src/app/cachedWorkflowReadPort.test.ts b/invokeai/frontend/webv2/src/app/cachedWorkflowReadPort.test.tsindex 21561d01f2..58750b1300 100644--- a/invokeai/frontend/webv2/src/app/cachedWorkflowReadPort.test.ts+++ b/invokeai/frontend/webv2/src/app/cachedWorkflowReadPort.test.ts@@ -39,4 +39,34 @@ describe('createCachedWorkflowReadPort', () => {expect(port.getSnapshot()).toEqual({ id: 'project-2' });expect(port.getSnapshot()).toBe(port.getSnapshot());});++ it('notifies every subscriber when one source change refreshes the shared cache', () => {+ let source = { projectId: 'project-1' };+ const sourceListeners = new Set<() => void>();+ const port = createCachedWorkflowReadPort(+ (listener) => {+ sourceListeners.add(listener);+ return () => sourceListeners.delete(listener);+ },+ () => source,+ (snapshot) => ({ id: snapshot.projectId }),+ shallowEqual+ );+ const firstListener = vi.fn();+ const secondListener = vi.fn();+ const unsubscribeFirst = port.subscribe(firstListener);+ const unsubscribeSecond = port.subscribe(secondListener);++ expect(sourceListeners.size).toBe(1);++ source = { projectId: 'project-2' };+ sourceListeners.forEach((notify) => notify());++ expect(firstListener).toHaveBeenCalledOnce();+ expect(secondListener).toHaveBeenCalledOnce();++ unsubscribeFirst();+ unsubscribeSecond();+ expect(sourceListeners.size).toBe(0);+ });});diff --git a/invokeai/frontend/webv2/src/app/cachedWorkflowReadPort.ts b/invokeai/frontend/webv2/src/app/cachedWorkflowReadPort.tsindex af2aefa7cd..8198248e6d 100644--- a/invokeai/frontend/webv2/src/app/cachedWorkflowReadPort.ts+++ b/invokeai/frontend/webv2/src/app/cachedWorkflowReadPort.ts@@ -10,6 +10,8 @@ export const createCachedWorkflowReadPort = <Source, Snapshot>(): WorkflowReadPort<Snapshot> => {let sourceSnapshot = getSourceSnapshot();let snapshot = mapSnapshot(sourceSnapshot);+ const listeners = new Set<() => void>();+ let unsubscribeSource: (() => void) | null = null;const refresh = (): boolean => {const nextSourceSnapshot = getSourceSnapshot();@@ -25,16 +27,32 @@ export const createCachedWorkflowReadPort = <Source, Snapshot>(return true;};+ const notifyIfChanged = (): void => {+ if (!refresh()) {+ return;+ }++ for (const listener of listeners) {+ listener();+ }+ };+return {getSnapshot: () => {refresh();return snapshot;},- subscribe: (listener) =>- subscribe(() => {- if (refresh()) {- listener();+ subscribe: (listener) => {+ listeners.add(listener);+ unsubscribeSource ??= subscribe(notifyIfChanged);++ return () => {+ listeners.delete(listener);+ if (listeners.size === 0) {+ unsubscribeSource?.();+ unsubscribeSource = null;}- }),+ };+ },};};diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/linear/WorkflowLinearPanel.browser.test.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/linear/WorkflowLinearPanel.browser.test.tsxnew file mode 100644index 0000000000..43cb7838a2--- /dev/null+++ b/invokeai/frontend/webv2/src/features/workflow/ui/linear/WorkflowLinearPanel.browser.test.tsx@@ -0,0 +1,57 @@+import { ChakraProvider } from '@chakra-ui/react';+import { system } from '@theme/system';+import { act, useState } from 'react';+import { createRoot, type Root } from 'react-dom/client';+import { afterEach, beforeEach, describe, expect, it } from 'vitest';+import { userEvent } from 'vitest/browser';++import { PanelModeToggle } from './WorkflowLinearPanel';++(globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;++describe('Workflow Linear panel mode toggle', () => {+ let host: HTMLDivElement;+ let root: Root;++ beforeEach(() => {+ host = document.createElement('div');+ document.body.append(host);+ root = createRoot(host);+ });++ afterEach(async () => {+ await act(() => root.unmount());+ host.remove();+ });++ it('activates View and Edit with pointer and keyboard button semantics', async () => {+ const Harness = () => {+ const [mode, setMode] = useState<'view' | 'edit'>('view');+ return <PanelModeToggle mode={mode} onChange={setMode} />;+ };++ await act(() => {+ root.render(+ <ChakraProvider value={system}>+ <Harness />+ </ChakraProvider>+ );+ });++ const buttons = host.querySelectorAll<HTMLButtonElement>('button[aria-pressed]');+ expect([...buttons].map((button) => button.getAttribute('aria-pressed'))).toEqual(['true', 'false']);++ await act(() => userEvent.click(buttons[1]!));+ expect([...buttons].map((button) => button.getAttribute('aria-pressed'))).toEqual(['false', 'true']);++ buttons[0]?.focus();+ await act(() => userEvent.keyboard('{Enter}'));+ expect([...buttons].map((button) => button.getAttribute('aria-pressed'))).toEqual(['true', 'false']);++ await act(() => userEvent.tab());+ expect(document.activeElement).toBe(buttons[1]);++ await act(() => userEvent.keyboard(' '));+ expect([...buttons].map((button) => button.getAttribute('aria-pressed'))).toEqual(['false', 'true']);+ });+});diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/linear/WorkflowLinearPanel.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/linear/WorkflowLinearPanel.tsxindex 10cf1cf63d..8a6039dda4 100644--- a/invokeai/frontend/webv2/src/features/workflow/ui/linear/WorkflowLinearPanel.tsx+++ b/invokeai/frontend/webv2/src/features/workflow/ui/linear/WorkflowLinearPanel.tsx@@ -1,8 +1,8 @@-import { Flex, HStack, Icon, SegmentGroup, Splitter } from '@chakra-ui/react';+import { Flex, HStack, Icon, Splitter } from '@chakra-ui/react';import { ensureInvocationTemplatesLoaded } from '@features/workflow/react';import { useWorkflowHostCommands, useWorkflowProjectSelector } from '@features/workflow/ui/WorkflowUiContext';import { useMountEffect } from '@platform/react/useMountEffect';-import { Scrollable, Tabs } from '@platform/ui';+import { Button, Scrollable, Tabs } from '@platform/ui';import { EyeIcon, PencilIcon } from 'lucide-react';import { useCallback, useMemo } from 'react';import { useTranslation } from 'react-i18next';@@ -64,28 +64,66 @@ export const getWorkflowPanelState = (values: Record<string, unknown>): Workflowexport const areWorkflowPanelStatesEqual = (left: WorkflowPanelState, right: WorkflowPanelState): boolean =>left.mode === right.mode && left.editTab === right.editTab && left.inspectorSizePct === right.inspectorSizePct;-const PanelModeToggle = ({ mode, onChange }: { mode: PanelMode; onChange: (mode: PanelMode) => void }) => {+export const PanelModeToggle = ({+ mode: currentMode,+ onChange,+}: {+ mode: PanelMode;+ onChange: (mode: PanelMode) => void;+}) => {const { t } = useTranslation();- const onValueChange = useCallback(- (details: { value: string | null }) => {- if (details.value === 'view' || details.value === 'edit') {- onChange(details.value);- }- },- [onChange]- );return (- <SegmentGroup.Root value={mode} onValueChange={onValueChange} size="xs">- <SegmentGroup.Indicator />- {PANEL_MODES.map(({ labelKey, icon, mode }) => (- <SegmentGroup.Item key={mode} value={mode}>- <SegmentGroup.ItemHiddenInput />- <Icon as={icon} boxSize="3" />- <SegmentGroup.ItemText>{t(labelKey)}</SegmentGroup.ItemText>- </SegmentGroup.Item>+ <HStack+ aria-label="Workflow panel mode"+ borderColor="border"+ borderRadius="md"+ borderWidth="1px"+ gap="0"+ overflow="hidden"+ role="group"+ >+ {PANEL_MODES.map(({ labelKey, icon, mode: itemMode }) => (+ <PanelModeButton+ key={itemMode}+ currentMode={currentMode}+ icon={icon}+ label={t(labelKey)}+ mode={itemMode}+ onChange={onChange}+ />))}- </SegmentGroup.Root>+ </HStack>+ );+};++const PanelModeButton = ({+ currentMode,+ icon,+ label,+ mode,+ onChange,+}: {+ currentMode: PanelMode;+ icon: typeof EyeIcon;+ label: string;+ mode: PanelMode;+ onChange: (mode: PanelMode) => void;+}) => {+ const onClick = useCallback(() => onChange(mode), [mode, onChange]);++ return (+ <Button+ aria-pressed={mode === currentMode}+ borderRadius="0"+ colorPalette={mode === currentMode ? 'accent' : 'bg'}+ size="xs"+ variant={mode === currentMode ? 'solid' : 'ghost'}+ onClick={onClick}+ >+ <Icon as={icon} boxSize="3" />+ {label}+ </Button>);};