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(ui): honest reload status for custom nodes
joshistoast6ddd99c8c1d0
diff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.jsonindex 46fc0a7592..f8a13b3b6c 100644--- a/invokeai/frontend/webv2/public/locales/en.json+++ b/invokeai/frontend/webv2/public/locales/en.json@@ -1211,6 +1211,7 @@"recentActivitySummary_one": "{{count}} recent activity","recentActivitySummary_other": "{{count}} recent activities","reloadFailed": "Reload failed",+ "reloadNotice": "Custom nodes reload","reloading": "Reloading","scanFolderDescription": "Add node packs directly to the custom nodes directory, then reload nodes. InvokeAI scans this folder on startup and reload.","searchPacks": "Search node packs",diff --git a/invokeai/frontend/webv2/src/features/nodes/data/api.test.ts b/invokeai/frontend/webv2/src/features/nodes/data/api.test.tsindex 7915ad69bc..3eccaa814d 100644--- a/invokeai/frontend/webv2/src/features/nodes/data/api.test.ts+++ b/invokeai/frontend/webv2/src/features/nodes/data/api.test.ts@@ -51,13 +51,15 @@ describe('custom node data adapter', () => {});});- it('forwards account cancellation to node reloads', async () => {+ it('forwards account cancellation to node reloads and returns the status body', async () => {+ adapter.requestJson.mockResolvedValue({ status: 'No custom nodes directory found.' });const { reloadCustomNodes } = await import('./api');const controller = new AbortController();- await reloadCustomNodes(controller.signal);-- expect(adapter.request).toHaveBeenCalledWith('/api/v2/custom_nodes/reload', {+ await expect(reloadCustomNodes(controller.signal)).resolves.toEqual({+ status: 'No custom nodes directory found.',+ });+ expect(adapter.requestJson).toHaveBeenCalledWith('/api/v2/custom_nodes/reload', {method: 'POST',signal: controller.signal,});diff --git a/invokeai/frontend/webv2/src/features/nodes/data/api.ts b/invokeai/frontend/webv2/src/features/nodes/data/api.tsindex 798b1c3973..7ace1957db 100644--- a/invokeai/frontend/webv2/src/features/nodes/data/api.ts+++ b/invokeai/frontend/webv2/src/features/nodes/data/api.ts@@ -5,7 +5,7 @@ import { browserNodesDataPort } from './transport';/** REST client for the custom nodes manager (`/api/v2/custom_nodes`). */const CUSTOM_NODES_BASE = '/api/v2/custom_nodes';-const { request, requestJson } = browserNodesDataPort;+const { requestJson } = browserNodesDataPort;export interface InstallNodePackResponse {name: string;@@ -38,6 +38,6 @@ export const uninstallCustomNodePack = (packName: string, signal?: AbortSignal):signal,});-export const reloadCustomNodes = async (signal?: AbortSignal): Promise<void> => {- await request(`${CUSTOM_NODES_BASE}/reload`, { method: 'POST', signal });-};+/** The body's status is prose (e.g. "No custom nodes directory found.") — callers must not assume success. */+export const reloadCustomNodes = (signal?: AbortSignal): Promise<{ status: string }> =>+ requestJson<{ status: string }>(`${CUSTOM_NODES_BASE}/reload`, { method: 'POST', signal });diff --git a/invokeai/frontend/webv2/src/features/nodes/ui/manager/ReloadNodesButton.browser.test.tsx b/invokeai/frontend/webv2/src/features/nodes/ui/manager/ReloadNodesButton.browser.test.tsxindex 69400d09e8..da3c9f726b 100644--- a/invokeai/frontend/webv2/src/features/nodes/ui/manager/ReloadNodesButton.browser.test.tsx+++ b/invokeai/frontend/webv2/src/features/nodes/ui/manager/ReloadNodesButton.browser.test.tsx@@ -12,6 +12,7 @@ const dependencies = vi.hoisted(() => ({refreshCustomNodePacks: vi.fn(),reloadCustomNodes: vi.fn(),success: vi.fn(),+ warning: vi.fn(),}));vi.mock('@features/nodes/data/api', () => ({ reloadCustomNodes: dependencies.reloadCustomNodes }));@@ -19,7 +20,7 @@ vi.mock('@features/nodes/data/nodesStore', () => ({refreshCustomNodePacks: dependencies.refreshCustomNodePacks,}));vi.mock('@features/nodes/ui/useNodesNotify', () => ({- useNotify: () => ({ error: dependencies.error, success: dependencies.success }),+ useNotify: () => ({ error: dependencies.error, success: dependencies.success, warning: dependencies.warning }),}));vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string) => key }) }));@@ -44,8 +45,9 @@ describe('ReloadNodesButton account ownership', () => {beforeEach(async () => {dependencies.error.mockReset();dependencies.refreshCustomNodePacks.mockReset().mockResolvedValue(undefined);- dependencies.reloadCustomNodes.mockReset().mockResolvedValue(undefined);+ dependencies.reloadCustomNodes.mockReset().mockResolvedValue({ status: 'Custom nodes reloaded successfully.' });dependencies.success.mockReset();+ dependencies.warning.mockReset();owner = accountLifecycle.activate('reload-nodes-a', ':user:reload-nodes-a');host = document.createElement('div');document.body.append(host);@@ -77,8 +79,21 @@ describe('ReloadNodesButton account ownership', () => {expect(dependencies.error).not.toHaveBeenCalled();});+ it('warns instead of celebrating when the backend reports a non-success status', async () => {+ dependencies.reloadCustomNodes.mockResolvedValueOnce({ status: 'No custom nodes directory found.' });++ await act(async () => {+ host.querySelector<HTMLButtonElement>('button')?.click();+ await vi.waitFor(() => expect(dependencies.warning).toHaveBeenCalledOnce());+ });++ expect(dependencies.warning).toHaveBeenCalledWith('nodes.reloadNotice', 'No custom nodes directory found.');+ expect(dependencies.success).not.toHaveBeenCalled();+ expect(dependencies.error).not.toHaveBeenCalled();+ });+it('keeps an account A abort quiet after account B activates', async () => {- const request = deferred<void>();+ const request = deferred<{ status: string }>();dependencies.reloadCustomNodes.mockReturnValueOnce(request.promise);await act(async () => {diff --git a/invokeai/frontend/webv2/src/features/nodes/ui/manager/ReloadNodesButton.tsx b/invokeai/frontend/webv2/src/features/nodes/ui/manager/ReloadNodesButton.tsxindex ad0484affc..af6c37d25f 100644--- a/invokeai/frontend/webv2/src/features/nodes/ui/manager/ReloadNodesButton.tsx+++ b/invokeai/frontend/webv2/src/features/nodes/ui/manager/ReloadNodesButton.tsx@@ -1,47 +1,42 @@-/* eslint-disable react-perf/jsx-no-jsx-as-prop, react-perf/jsx-no-new-array-as-prop, react-perf/jsx-no-new-function-as-prop, react-perf/jsx-no-new-object-as-prop */+/* eslint-disable react-perf/jsx-no-jsx-as-prop, react-perf/jsx-no-new-function-as-prop */import { Icon } from '@chakra-ui/react';import { reloadCustomNodes } from '@features/nodes/data/api';import { refreshCustomNodePacks } from '@features/nodes/data/nodesStore';import { useNotify } from '@features/nodes/ui/useNodesNotify';-import {- assertAccountScopeCurrent,- captureAccountScope,- isAccountScopeCurrent,-} from '@platform/state/accountLifecycle';+import { useScopedAction } from '@platform/react/useScopedAction';+import { assertAccountScopeCurrent } from '@platform/state/accountLifecycle';import { getApiErrorMessage } from '@platform/transport/http';import { Button } from '@platform/ui';import { RefreshCwIcon } from 'lucide-react';-import { useState } from 'react';import { useTranslation } from 'react-i18next';export const ReloadNodesButton = () => {const notify = useNotify();const { t } = useTranslation();- const [isReloading, setIsReloading] = useState(false);+ const { isBusy: isReloading, run } = useScopedAction();- const handleReload = async () => {- const owner = captureAccountScope();+ const handleReload = () =>+ run(+ async (owner) => {+ const { status } = await reloadCustomNodes(owner.signal);- setIsReloading(true);+ assertAccountScopeCurrent(owner);+ await refreshCustomNodePacks(owner);+ assertAccountScopeCurrent(owner);- try {- await reloadCustomNodes(owner.signal);- assertAccountScopeCurrent(owner);- await refreshCustomNodePacks(owner);- assertAccountScopeCurrent(owner);- notify.success(t('nodes.customNodesReloaded'));- } catch (error) {- if (!isAccountScopeCurrent(owner)) {- return;- }-- notify.error(t('nodes.reloadFailed'), getApiErrorMessage(error, t('nodes.couldNotReloadCustomNodes')));- } finally {- if (isAccountScopeCurrent(owner)) {- setIsReloading(false);- }- }- };+ // The backend reports the outcome as prose (custom_nodes.py). Only+ // its success phrasing earns a green toast; anything else — like+ // "No custom nodes directory found." — surfaces as-is. Unknown+ // statuses fail honest, never fail green.+ if (status.startsWith('Custom nodes reloaded')) {+ notify.success(t('nodes.customNodesReloaded'));+ } else {+ notify.warning(t('nodes.reloadNotice'), status);+ }+ },+ (_message, error) =>+ notify.error(t('nodes.reloadFailed'), getApiErrorMessage(error, t('nodes.couldNotReloadCustomNodes')))+ );return (<Button loading={isReloading} size="2xs" variant="ghost" onClick={() => void handleReload()}>@@ -50,4 +45,3 @@ export const ReloadNodesButton = () => {</Button>);};-/* eslint-disable react-perf/jsx-no-jsx-as-prop, react-perf/jsx-no-new-array-as-prop, react-perf/jsx-no-new-function-as-prop, react-perf/jsx-no-new-object-as-prop */