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(webv2): one-shot add-models seed and honest preview height test
joshistoast0f2156fb6a1f
diff --git a/invokeai/frontend/webv2/src/features/models/ui/add-models/AddModelsView.browser.test.tsx b/invokeai/frontend/webv2/src/features/models/ui/add-models/AddModelsView.browser.test.tsxnew file mode 100644index 0000000000..9424b38579--- /dev/null+++ b/invokeai/frontend/webv2/src/features/models/ui/add-models/AddModelsView.browser.test.tsx@@ -0,0 +1,119 @@+import { ChakraProvider } from '@chakra-ui/react';+import { system } from '@theme/system';+import { act, StrictMode } from 'react';+import { createRoot, type Root } from 'react-dom/client';+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';++import { AddModelsView } from './AddModelsView';++/**+ * The Add Models box is local state seeded once from the models UI store, so a+ * requirement link elsewhere in the app can open this view already searching —+ * without that search outliving the view the way account-scoped store state+ * would. This suite owns exactly that handover; everything else the view does+ * is stubbed out.+ */++vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string) => key }) }));++vi.mock('@features/models/data/startersStore', async (importOriginal) => ({+ ...(await importOriginal<Record<string, unknown>>()),+ ensureStartersLoaded: vi.fn(),+ useStartersSelector: (selector: (snapshot: unknown) => unknown) =>+ selector({ error: null, response: { starter_bundles: {}, starter_models: [] }, status: 'loaded' }),+}));++vi.mock('@features/models/data/externalProvidersStore', async (importOriginal) => ({+ ...(await importOriginal<Record<string, unknown>>()),+ ensureExternalProvidersLoaded: () => Promise.resolve(),+ useExternalProvidersSelector: (selector: (snapshot: unknown) => unknown) => selector({ configs: [] }),+}));++// Spread the original: sibling modules in this view's graph import other+// members of it, and a narrow factory would break their imports outright.+vi.mock('@features/models/data/api', async (importOriginal) => ({+ ...(await importOriginal<Record<string, unknown>>()),+ getHuggingFaceModels: vi.fn(),+ scanFolderForModels: vi.fn(),+}));++vi.mock('./useInstallActions', () => ({+ useInstallActions: () => ({ install: vi.fn(), installMany: vi.fn(), pendingSources: new Set() }),+}));++vi.mock('@features/models/ui/useModelsNotify', () => ({+ useNotify: () => ({ error: vi.fn(), info: vi.fn(), success: vi.fn() }),+}));++(globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;++describe('AddModelsView search seed', () => {+ let host: HTMLDivElement;+ let root: Root;++ const searchBox = () => document.querySelector<HTMLInputElement>('input[aria-label="models.searchOrAdd"]');++ const mount = async () => {+ root = createRoot(host);++ await act(async () => {+ root.render(+ <StrictMode>+ <ChakraProvider value={system}>+ <AddModelsView />+ </ChakraProvider>+ </StrictMode>+ );+ // Chakra's observer-driven commits land a task after the render that+ // armed them; awaiting inside this scope keeps them in it.+ await new Promise<void>((resolve) => {+ setTimeout(resolve, 0);+ });+ });+ };++ const unmount = async () => {+ await act(() => root.unmount());+ };++ beforeEach(async () => {+ host = document.createElement('div');+ document.body.append(host);++ const store = await import('@features/models/ui/uiStore');+ store.clearAddModelsSeed();+ });++ afterEach(() => {+ host.remove();+ });++ it('opens searching for a seeded model, then forgets it on the next open', async () => {+ const { requestAddModelsSearch } = await import('@features/models/ui/uiStore');++ requestAddModelsSearch('Wan 2.2 I2V A14B');+ await mount();++ // StrictMode double-invokes the `useState` initializer, so the read has to+ // survive being run twice — this is the case that catches a take-and-clear+ // initializer.+ expect(searchBox()?.value).toBe('Wan 2.2 I2V A14B');++ await unmount();+ await mount();++ // A tab switch used to reset the box, and still does: the seed was+ // one-shot, not account-lived state that keeps filtering hours later.+ expect(searchBox()?.value).toBe('');++ await unmount();+ });++ it('opens empty when nothing asked it to search', async () => {+ await mount();++ expect(searchBox()?.value).toBe('');++ await unmount();+ });+});diff --git a/invokeai/frontend/webv2/src/features/models/ui/add-models/AddModelsView.tsx b/invokeai/frontend/webv2/src/features/models/ui/add-models/AddModelsView.tsxindex 3590de8fa3..436612326f 100644--- a/invokeai/frontend/webv2/src/features/models/ui/add-models/AddModelsView.tsx+++ b/invokeai/frontend/webv2/src/features/models/ui/add-models/AddModelsView.tsx@@ -15,7 +15,7 @@ import {useExternalProvidersSelector,} from '@features/models/data/externalProvidersStore';import { ensureStartersLoaded, useStartersSelector } from '@features/models/data/startersStore';-import { updateModelsUi, useModelsUiSelector } from '@features/models/ui/uiStore';+import { clearAddModelsSeed, getAddModelsSeed, updateModelsUi, useModelsUiSelector } from '@features/models/ui/uiStore';import { useNotify } from '@features/models/ui/useModelsNotify';import { useMountEffect } from '@platform/react/useMountEffect';import { useScopedAction } from '@platform/react/useScopedAction';@@ -63,24 +63,23 @@ export const AddModelsView = () => {const loadError = useStartersSelector((snapshot) => snapshot.error);const response = useStartersSelector((snapshot) => snapshot.response);const status = useStartersSelector((snapshot) => snapshot.status);- const { hfLookup, query, scan, selectedBundleName } = useModelsUiSelector(+ const { hfLookup, scan, selectedBundleName } = useModelsUiSelector((snapshot) => ({hfLookup: snapshot.hfLookup,- query: snapshot.addModelsQuery,scan: snapshot.scan,selectedBundleName: snapshot.selectedBundleName,}),(left, right) =>left.hfLookup === right.hfLookup &&- left.query === right.query &&left.scan === right.scan &&left.selectedBundleName === right.selectedBundleName);- // In the store rather than local state so another surface can seed it before- // navigating here (`requestAddModelsSearch`) without this view needing an- // effect to notice.- const setQuery = (addModelsQuery: string) => updateModelsUi({ addModelsQuery });+ // Local state, so the box empties when the view unmounts (a tab switch) — but+ // seeded once from whatever asked to search here on the way in. The read is+ // pure, because StrictMode double-invokes this initializer; the consuming+ // clear is the mount effect below.+ const [query, setQuery] = useState(getAddModelsSeed);const [accessToken, setAccessToken] = useState('');const [inplace, setInplace] = useState(true);const { isBusy: isPulling, run: runPull } = useScopedAction();@@ -97,6 +96,8 @@ export const AddModelsView = () => {const [starterFilters, setStarterFilters] = useState<StarterModelFilters>(DEFAULT_STARTER_MODEL_FILTERS);useMountEffect(() => {+ // One-shot: a seed only ever fills the box the view was opened with.+ clearAddModelsSeed();ensureStartersLoaded();const owner = captureAccountScope();diff --git a/invokeai/frontend/webv2/src/features/models/ui/uiStore.test.ts b/invokeai/frontend/webv2/src/features/models/ui/uiStore.test.tsindex 09e4a737d4..1515a41627 100644--- a/invokeai/frontend/webv2/src/features/models/ui/uiStore.test.ts+++ b/invokeai/frontend/webv2/src/features/models/ui/uiStore.test.ts@@ -28,7 +28,6 @@ describe('models ui store', () => {store.updateModelsUi({activeTab: 'details',- addModelsQuery: 'stale',hfLookup: { repo: 'owner/repo', urls: ['a'] },scan: { path: '/models', results: [] },selectedBundleName: 'Essentials',@@ -41,12 +40,29 @@ describe('models ui store', () => {// Add Models, showing the starter catalog filtered to the request — a// leftover scan/HF panel or bundle would hide the catalog entirely.expect(snapshot.activeTab).toBe('add');- expect(snapshot.addModelsQuery).toBe('Juggernaut XL');+ expect(store.getAddModelsSeed()).toBe('Juggernaut XL');expect(snapshot.hfLookup).toBeNull();expect(snapshot.scan).toBeNull();expect(snapshot.selectedBundleName).toBeNull();});+ it('hands the Add Models seed over exactly once', async () => {+ const store = await import('./uiStore');++ expect(store.getAddModelsSeed()).toBe('');++ store.requestAddModelsSearch('Juggernaut XL');++ // Reading is pure — StrictMode double-invokes the initializer that reads it.+ expect(store.getAddModelsSeed()).toBe('Juggernaut XL');+ expect(store.getAddModelsSeed()).toBe('Juggernaut XL');++ store.clearAddModelsSeed();++ // The next time Add Models opens on its own, the box is empty again.+ expect(store.getAddModelsSeed()).toBe('');+ });+it('keeps the bundle selection until it is explicitly replaced', async () => {const store = await import('./uiStore');diff --git a/invokeai/frontend/webv2/src/features/models/ui/uiStore.ts b/invokeai/frontend/webv2/src/features/models/ui/uiStore.tsindex edc85d27bf..f0413887f1 100644--- a/invokeai/frontend/webv2/src/features/models/ui/uiStore.ts+++ b/invokeai/frontend/webv2/src/features/models/ui/uiStore.ts@@ -29,11 +29,13 @@ export interface HFLookupState {export interface ModelsUiSnapshot {activeTab: ModelManagerTab;/**- * The Add Models box's contents. Session state like everything else here, so- * a half-typed source survives a tab switch — and so surfaces outside the- * manager can seed it before navigating (see {@link requestAddModelsSearch}).+ * A pending Add Models search, handed over by a surface outside the manager+ * (see {@link requestAddModelsSearch}). Strictly one-shot: the view takes it+ * at mount and {@link clearAddModelsSeed} empties it, so the box keeps its own+ * local state and still resets when the view unmounts. `null` = nothing+ * pending, which is not the same as a seeded empty string.*/- addModelsQuery: string;+ addModelsSeed: string | null;/** Model focused in the manager library's detail pane. */activeModelKey: string | null;selectedKeys: ReadonlySet<string>;@@ -55,7 +57,7 @@ export interface ModelsUiSnapshot {const createInitialModelsUiSnapshot = (): ModelsUiSnapshot => ({activeModelKey: null,activeTab: 'add',- addModelsQuery: '',+ addModelsSeed: null,filters: { ...DEFAULT_LIBRARY_FILTERS },hfLookup: null,libraryScrollOffsets: {},@@ -134,13 +136,29 @@ export const openAddModelsWithBundle = (bundleName: string): void => {export const requestAddModelsSearch = (query: string): void => {updateModelsUi({activeTab: 'add',- addModelsQuery: query,+ addModelsSeed: query,hfLookup: null,scan: null,selectedBundleName: null,});};+/** Reads a pending seed without consuming it — safe to call from a `useState` initializer, which StrictMode double-invokes. */+export const getAddModelsSeed = (): string => store.getSnapshot().addModelsSeed ?? '';++/**+ * Consumes the pending seed. Silent because the only reader took it in the same+ * commit and nothing subscribes to it: a notify here would be a store write+ * whose only effect is re-rendering the view that just read it.+ */+export const clearAddModelsSeed = (): void => {+ const snapshot = store.getSnapshot();++ if (snapshot.addModelsSeed !== null) {+ store.setSnapshotSilently({ ...snapshot, addModelsSeed: null });+ }+};+/** Expand the always-visible install queue footer (e.g. from a "View queue" link). */export const openInstallQueue = (): void => {updateModelsUi({ queueExpanded: true });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.tsxindex ec0217abcb..77aa132d59 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@@ -12,6 +12,7 @@ import { system } from '@theme/system';import { act, StrictMode } from 'react';import { createRoot, type Root } from 'react-dom/client';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';+import { page } from 'vitest/browser';import { GraphPreviewDialog } from './GraphPreviewDialog';@@ -521,15 +522,28 @@ describe('GraphPreviewDialog', () => {});});- it('caps its height so a tall display gets a landscape dialog, not a full-height column', async () => {- await renderDialog(FIXTURE_SOURCE);+ it('stays landscape on a tall viewport instead of growing into a full-height column', async () => {+ const original = { height: window.innerHeight, width: window.innerWidth };++ try {+ // Resized deliberately: at the default test viewport (~866px tall) an+ // 80vh dialog and a 46rem-capped one measure within pixels of each other,+ // so nothing asserted at that size can tell the two sizings apart.+ await page.viewport(1280, 1400);+ await renderDialog(FIXTURE_SOURCE);- const content = document.querySelector<HTMLElement>('[data-scope="dialog"][data-part="content"]');- expect(content).not.toBeNull();+ const content = document.querySelector<HTMLElement>('[data-scope="dialog"][data-part="content"]');+ expect(content).not.toBeNull();- // 46rem — the ceiling that makes the dialog wider than tall wherever the- // viewport is tall enough for the old vh-driven height to overshoot it.- expect(content?.getBoundingClientRect().height ?? 0).toBeLessThanOrEqual(46 * 16 + 1);+ const box = content?.getBoundingClientRect();++ // A viewport-proportional height would be ~1100px here; the cap is 46rem.+ expect(box?.height ?? 0).toBeLessThanOrEqual(46 * 16 + 1);+ // Which leaves the dialog the shape a graph reads in.+ expect(box?.width ?? 0).toBeGreaterThan(box?.height ?? 0);+ } finally {+ await page.viewport(original.width, original.height);+ }});it('shows the seed notice inline in the summary panel', async () => {