diff --git a/src/canvas/generationActivity.ts b/src/canvas/generationActivity.ts index bb7ad8a6..031e7fd8 100644 --- a/src/canvas/generationActivity.ts +++ b/src/canvas/generationActivity.ts @@ -9,15 +9,18 @@ export function jobActivities( documentId: string, nodes: readonly CanvasNode[] = [], ): ActiveGeneration[] { - const displayed = new Map(nodes.map((node) => [node.id, node.data.backendAssetId])); + const byId = new Map(nodes.map((node) => [node.id, node])); return jobs.flatMap((job) => { - // A regenerated node keeps its old media until the new result has loaded; - // stay busy until then rather than briefly revealing the old image. + // A node keeps its old media, or shows an empty frame, until the new result + // has loaded; stay busy until then. Locally edited text has content but no + // backend asset, and is not waiting for anything. + const node = byId.get(job.nodeId); + const shown = node?.data.backendAssetId; + const empty = Boolean(node && !node.data.src && !node.data.text); const delivering = Boolean( job.status === "succeeded" && job.deliveredAssetId && - displayed.has(job.nodeId) && - displayed.get(job.nodeId) !== job.deliveredAssetId, + (shown ? shown !== job.deliveredAssetId : empty), ); const finishing = delivering || Boolean( job.toolTask && diff --git a/src/canvas/workspace/useWorkspaceRuntime.ts b/src/canvas/workspace/useWorkspaceRuntime.ts index 15463120..2501156b 100644 --- a/src/canvas/workspace/useWorkspaceRuntime.ts +++ b/src/canvas/workspace/useWorkspaceRuntime.ts @@ -153,6 +153,11 @@ export function useWorkspaceRuntime(): WorkspaceRuntime { const setupChecked = useRef(false); const theme = useTheme(); const serviceRuns = useRef(new Map()); + // Jobs seen running in this session. Only their results can still be + // arriving; historical, undone or version-switched results are never pending. + const watchedJobs = useRef(new Set()); + for (const job of jobs) + if (!job.tool && job.status === "running") watchedJobs.current.add(job.id); const generationByNode = useMemo( () => generationActivities( @@ -167,7 +172,13 @@ export function useWorkspaceRuntime(): WorkspaceRuntime { ), ), ...jobActivities( - jobs.filter((job) => !job.tool), + jobs + .filter((job) => !job.tool) + .map((job) => + job.deliveredAssetId && !watchedJobs.current.has(job.id) + ? { ...job, deliveredAssetId: undefined } + : job, + ), doc.id, doc.nodes, ), diff --git a/tests/canvasPendingResults.test.ts b/tests/canvasPendingResults.test.ts index 0d790b5b..7ed452fb 100644 --- a/tests/canvasPendingResults.test.ts +++ b/tests/canvasPendingResults.test.ts @@ -423,6 +423,12 @@ test("a regenerated node stays busy until its delivered result is displayed", () const shown = { ...node, data: { ...node.data, backendAssetId: "new-asset" } }; assert.deepEqual(jobActivities([job], "doc", [shown]), []); assert.deepEqual(jobActivities([job], "doc", []), []); + // Local text edits clear the backend asset; such a node is not waiting. + const edited = { ...node, data: { ...node.data, backendAssetId: undefined, text: "draft" } }; + assert.deepEqual(jobActivities([job], "doc", [edited]), []); + // A first generation into an empty node waits instead of flashing an empty frame. + const fresh = { ...node, data: { ...node.data, backendAssetId: undefined, src: undefined, text: undefined } }; + assert.equal(jobActivities([job], "doc", [fresh])[0]?.phase, "finishing"); // A succeeded job whose result is not the node's current content stays idle. assert.deepEqual(jobActivities([{ ...job, deliveredAssetId: undefined }], "doc", [node]), []); });