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(workflow): refresh captions when workflow data changes

Josh Corbettd8bf7d8fca3a
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/library/ProjectWorkflowsView.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/library/ProjectWorkflowsView.tsx
index aa34074034..d3a45e40da 100644
--- a/invokeai/frontend/webv2/src/features/workflow/ui/library/ProjectWorkflowsView.tsx
+++ b/invokeai/frontend/webv2/src/features/workflow/ui/library/ProjectWorkflowsView.tsx
@@ -32,7 +32,7 @@ import {
isUpdatableSource,
toProjectWorkflowLibraryEntries,
} from './projectWorkflowEntries';
-import { formatTimeSince } from './relativeTime';
+import { formatTimeSince, useDataTimeSnapshot } from './relativeTime';
import {
getWorkflowLibraryCardId,
getWorkflowLibraryCardMenuContentId,
@@ -241,7 +241,7 @@ const ProjectWorkflowDetailPanel = ({
const templatesSnapshot = useInvocationTemplatesSnapshot();
const openAddModels = useOpenAddModels();
const [failedThumbnailUrl, setFailedThumbnailUrl] = useState<string | null>(null);
- const [openedAt] = useState(() => new Date());
+ const dataTime = useDataTimeSnapshot(entry);
const libraryEntry = useMemo(
() =>
@@ -323,7 +323,7 @@ const ProjectWorkflowDetailPanel = ({
const name = entryName;
const thumbnailUrl = libraryEntry.item.thumbnail_url;
const showThumbnail = Boolean(thumbnailUrl) && thumbnailUrl !== failedThumbnailUrl;
- const lastRun = entry.lastRun ? formatTimeSince(entry.lastRun.completedAt, openedAt) : '';
+ const lastRun = entry.lastRun ? formatTimeSince(entry.lastRun.completedAt, dataTime) : '';
const source = entry.source;
const canUpdateSource = isUpdatableSource(source, session);
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryDetailPanel.browser.test.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryDetailPanel.browser.test.tsx
index 7f49d3f41c..b45736ec70 100644
--- a/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryDetailPanel.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryDetailPanel.browser.test.tsx
@@ -540,6 +540,26 @@ describe('WorkflowLibraryDetailPanel', () => {
expect(models.ensureStartersLoaded).toHaveBeenCalled();
});
+ it('ages a run after mount when refreshed workflow data arrives', async () => {
+ vi.useFakeTimers({ toFake: ['Date'] });
+
+ try {
+ vi.setSystemTime(new Date('2026-10-20T10:00:00Z'));
+ await renderPanel({ ...TEXT_TO_IMAGE, item: { ...TEXT_TO_IMAGE.item, last_run_at: null } });
+
+ vi.setSystemTime(new Date('2026-10-20T10:05:00Z'));
+ const ran = { ...TEXT_TO_IMAGE, item: { ...TEXT_TO_IMAGE.item, last_run_at: '2026-10-20T10:05:00Z' } };
+ await renderPanel(ran);
+ expect(panel()?.textContent).toContain('Your last run · now');
+
+ vi.setSystemTime(new Date('2026-10-20T12:00:00Z'));
+ await renderPanel({ ...ran, item: { ...ran.item } });
+ expect(panel()?.textContent).toContain('Your last run · 2 hours ago');
+ } finally {
+ vi.useRealTimers();
+ }
+ });
+
it('changes visibility by keyboard, stays server-driven while pending, then reflects the response and invalidates', async () => {
let resolveChange: (record: { is_public: boolean }) => void = NOOP;
queries.setLibraryWorkflowPublic.mockImplementationOnce(
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryThumbnail.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryThumbnail.tsx
index aff6ef67f5..eea3e3f8f8 100644
--- a/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryThumbnail.tsx
+++ b/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryThumbnail.tsx
@@ -28,7 +28,7 @@ import { Suspense, useCallback, useRef, useState, type MouseEvent } from 'react'
import { useTranslation } from 'react-i18next';
import { buildLibraryGraphPreviewSource, DeferredGraphPreviewSnapshot, loadGraphPreview } from './libraryPreviewSource';
-import { formatTimeSince } from './relativeTime';
+import { formatTimeSince, useDataTimeSnapshot } from './relativeTime';
import { WORKFLOW_THUMBNAIL_ASPECT_RATIO, WorkflowThumbnailImage } from './workflowThumbnail';
const IMAGE_ONLY = ['image'] as const;
@@ -58,7 +58,7 @@ export const WorkflowLibraryThumbnail = ({
const notify = useWorkflowNotifications();
// Keyed by URL: a replaced image arrives under a fresh URL and re-arms the thumbnail.
const [failedThumbnailUrl, setFailedThumbnailUrl] = useState<string | null>(null);
- const [openedAt] = useState(() => new Date());
+ const dataTime = useDataTimeSnapshot(item);
// Local rather than `useScopedAction`: the library ships in the editor boot graph, and a second importer of that
// models-only hook splits it into its own startup chunk.
const [isBusy, setIsBusy] = useState(false);
@@ -226,7 +226,7 @@ export const WorkflowLibraryThumbnail = ({
);
const showThumbnail = Boolean(item.thumbnail_url) && item.thumbnail_url !== failedThumbnailUrl;
- const lastRun = item.last_run_at ? formatTimeSince(item.last_run_at, openedAt) : '';
+ const lastRun = item.last_run_at ? formatTimeSince(item.last_run_at, dataTime) : '';
// A user template's thumbnail is always one someone set; only bundled defaults ship a sample output.
const caption = lastRun
? t('workflowLibrary.lastRun', { when: lastRun })
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowPublicationHost.browser.test.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowPublicationHost.browser.test.tsx
index 4d7b009706..10417b4729 100644
--- a/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowPublicationHost.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowPublicationHost.browser.test.tsx
@@ -1,10 +1,14 @@
import type { ProjectWorkflowEntry } from '@features/workflow/core/types';
import type { WorkflowRecordDTO } from '@features/workflow/data/api';
-import type { WorkflowReadPort, WorkflowUiAdapter } from '@features/workflow/ui/WorkflowUiContext';
+import type {
+ WorkflowGraphPreviewPort,
+ WorkflowReadPort,
+ WorkflowUiAdapter,
+} from '@features/workflow/ui/WorkflowUiContext';
import { ChakraProvider } from '@chakra-ui/react';
import { WorkflowLibraryWriteRefusedError } from '@features/workflow/data/api';
-import { WorkflowUiProvider } from '@features/workflow/ui/WorkflowUiContext';
+import { WorkflowGraphPreviewProvider, WorkflowUiProvider } from '@features/workflow/ui/WorkflowUiContext';
import { requestWorkflowPublication, workflowUiStore } from '@features/workflow/ui/workflowUiStore';
import { createProjectGraph, serializeWorkflowJson } from '@features/workflow/utility';
import { accountLifecycle } from '@platform/state/accountLifecycle';
@@ -14,6 +18,7 @@ import { act, StrictMode } from 'react';
import { createRoot, type Root } from 'react-dom/client';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import { loadGraphPreview } from './libraryPreviewSource';
import { WorkflowPublicationHost } from './WorkflowPublicationHost';
/**
@@ -151,6 +156,13 @@ const LINKED_UNKNOWN: ProjectWorkflowEntry = {
};
const BUNDLED: ProjectWorkflowEntry = { ...UNLINKED, source: { libraryWorkflowId: 'default_alpha', revision: 1 } };
const OTHER: ProjectWorkflowEntry = { document: { ...createProjectGraph('wf-2'), name: 'Beta' } };
+const GRAPH_PREVIEW: WorkflowGraphPreviewPort = {
+ focusSource: vi.fn(),
+ getRoute: () => null,
+ invoke: () => Promise.resolve(false),
+ openDocumentInNewProject: vi.fn(),
+ openWorkflowEditor: vi.fn(),
+};
const projectSnapshot = (workflows: readonly ProjectWorkflowEntry[]) => ({
activeWorkflow: workflows[0]!,
@@ -228,7 +240,9 @@ describe('WorkflowPublicationHost', () => {
<QueryClientProvider client={new QueryClient({ defaultOptions: { queries: { retry: false } } })}>
<ChakraProvider value={system}>
<WorkflowUiProvider adapter={adapter}>
- <WorkflowPublicationHost />
+ <WorkflowGraphPreviewProvider adapter={GRAPH_PREVIEW}>
+ <WorkflowPublicationHost />
+ </WorkflowGraphPreviewProvider>
</WorkflowUiProvider>
</ChakraProvider>
</QueryClientProvider>
@@ -635,6 +649,31 @@ describe('WorkflowPublicationHost', () => {
expect(dialogs()).toHaveLength(0);
});
+ it('dates the revision against the arriving review record instead of the loading view mount', async () => {
+ await loadGraphPreview();
+ vi.useFakeTimers({ toFake: ['Date'] });
+
+ try {
+ vi.setSystemTime(new Date('2026-10-20T10:00:00Z'));
+ const pendingRecord = deferred<WorkflowRecordDTO>();
+ api.getLibraryWorkflowRecord.mockReturnValue(pendingRecord.promise);
+ await renderHost([LINKED_UNKNOWN]);
+ await request('update-source');
+ await click(choice('review'));
+ expect(reviewDialog()?.textContent).toContain('Loading the current template…');
+
+ vi.setSystemTime(new Date('2026-10-20T12:00:00Z'));
+ await act(async () => {
+ pendingRecord.resolve(record({ revision: 5, updated_at: '2026-10-20T10:05:00Z' }));
+ await settleFrame();
+ });
+
+ expect(reviewDialog()?.textContent).toContain('Revision 5 · updated 2 hours ago');
+ } finally {
+ vi.useRealTimers();
+ }
+ });
+
it('lets a conflict be resolved by saving as a new template instead', async () => {
await renderHost([LINKED_UNKNOWN]);
await request('update-source');
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowPublicationHost.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowPublicationHost.tsx
index 7ca3902204..d10673e55f 100644
--- a/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowPublicationHost.tsx
+++ b/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowPublicationHost.tsx
@@ -31,7 +31,7 @@ import {
preloadGraphPreview,
} from './libraryPreviewSource';
import { isBundledLibraryWorkflowId, isUpdatableSource } from './projectWorkflowEntries';
-import { formatTimeSince } from './relativeTime';
+import { formatTimeSince, useDataTimeSnapshot } from './relativeTime';
import {
discardUnresolvedWorkflowPublication,
getUnresolvedWorkflowPublication,
@@ -601,7 +601,7 @@ const ReviewBody = ({
onPreview: (() => void) | undefined;
}) => {
const { t } = useTranslation();
- const [openedAt] = useState(() => new Date());
+ const dataTime = useDataTimeSnapshot(record);
if (error) {
return (
@@ -636,7 +636,7 @@ const ReviewBody = ({
<Text color="fg.subtle" fontSize="xs">
{t('workflowLibrary.reviewRevision', {
revision: record.revision,
- when: record.updated_at ? formatTimeSince(record.updated_at, openedAt) : '',
+ when: record.updated_at ? formatTimeSince(record.updated_at, dataTime) : '',
})}
</Text>
</Stack>
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/library/relativeTime.ts b/invokeai/frontend/webv2/src/features/workflow/ui/library/relativeTime.ts
index 7a6d806615..05f3646422 100644
--- a/invokeai/frontend/webv2/src/features/workflow/ui/library/relativeTime.ts
+++ b/invokeai/frontend/webv2/src/features/workflow/ui/library/relativeTime.ts
@@ -1,5 +1,7 @@
/** Inject current time so relative captions remain deterministic. */
+import { useState } from 'react';
+
const DIVISIONS: readonly { amount: number; unit: Intl.RelativeTimeFormatUnit }[] = [
{ amount: 60, unit: 'second' },
{ amount: 60, unit: 'minute' },
@@ -34,10 +36,18 @@ export const formatRelativeTime = (timestamp: string, now: Date): string => {
};
/**
- * Caption for a past event (last run, last update), read against a clock snapshot the component takes once per mount:
- * the React Compiler memoizes render output, so reading the clock during render would be stale anyway. A timestamp
- * newer than the snapshot is either server clock skew or an event since mount; both mean "just happened", so it reads
- * as "now" rather than "in X". Use `formatRelativeTime` directly where future times are meaningful.
+ * Past-event captions clamp server clock skew to "now". Use `formatRelativeTime` where future times are meaningful.
*/
export const formatTimeSince = (timestamp: string, snapshot: Date): string =>
formatRelativeTime(timestamp, new Date(Math.max(snapshot.getTime(), Date.parse(timestamp))));
+
+/** Data refreshes advance the clock without resetting the view's other local state. */
+export const useDataTimeSnapshot = (data: object | null | undefined): Date => {
+ const [snapshot, setSnapshot] = useState(() => ({ data, now: new Date() }));
+
+ if (snapshot.data !== data) {
+ setSnapshot(() => ({ data, now: new Date() }));
+ }
+
+ return snapshot.now;
+};