Skip to content

Commit f366640

Browse files
fix(ui): invoke button not showing loading indicator on canvas tab
On the Canvas tab, when we made the network request to enqueue a batch, we were immediately resetting the request. This effectively disabled RTKQ's tracking of the request - including the loading state. As a result, when you click the Invoke button on the Canvas tab, it didn't show a spinner, and it was not clear that anything was happening. The solution is simple - just await the enqueue request before resetting the tracking, same as we already did on the workflows and upscaling tabs. I also added some extra logging messages for enqueuing, so we get the same JS console logs for each tab on success or failure.
1 parent 36a3fba commit f366640

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/enqueueRequestedLinear.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { enqueueRequested } from 'app/store/actions';
33
import type { AppStartListening } from 'app/store/middleware/listenerMiddleware';
44
import { extractMessageFromAssertionError } from 'common/util/extractMessageFromAssertionError';
55
import { withResult, withResultAsync } from 'common/util/result';
6+
import { parseify } from 'common/util/serialize';
67
import { $canvasManager } from 'features/controlLayers/store/ephemeral';
78
import { prepareLinearUIBatch } from 'features/nodes/util/graph/buildLinearBatchConfig';
89
import { buildFLUXGraph } from 'features/nodes/util/graph/generation/buildFLUXGraph';
@@ -13,7 +14,6 @@ import { toast } from 'features/toast/toast';
1314
import { serializeError } from 'serialize-error';
1415
import { enqueueMutationFixedCacheKeyOptions, queueApi } from 'services/api/endpoints/queue';
1516
import { assert, AssertionError } from 'tsafe';
16-
import type { JsonObject } from 'type-fest';
1717

1818
const log = logger('generation');
1919

@@ -80,16 +80,15 @@ export const addEnqueueRequestedLinear = (startAppListening: AppStartListening)
8080
const req = dispatch(
8181
queueApi.endpoints.enqueueBatch.initiate(prepareBatchResult.value, enqueueMutationFixedCacheKeyOptions)
8282
);
83-
req.reset();
8483

85-
const enqueueResult = await withResultAsync(() => req.unwrap());
86-
87-
if (enqueueResult.isErr()) {
88-
log.error({ error: serializeError(enqueueResult.error) }, 'Failed to enqueue batch');
89-
return;
84+
try {
85+
await req.unwrap();
86+
log.debug(parseify({ batchConfig: prepareBatchResult.value }), 'Enqueued batch');
87+
} catch (error) {
88+
log.error({ error: serializeError(error) }, 'Failed to enqueue batch');
89+
} finally {
90+
req.reset();
9091
}
91-
92-
log.debug({ batchConfig: prepareBatchResult.value } as JsonObject, 'Enqueued batch');
9392
},
9493
});
9594
};

invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/enqueueRequestedNodes.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1+
import { logger } from 'app/logging/logger';
12
import { enqueueRequested } from 'app/store/actions';
23
import type { AppStartListening } from 'app/store/middleware/listenerMiddleware';
4+
import { parseify } from 'common/util/serialize';
35
import { $templates } from 'features/nodes/store/nodesSlice';
46
import { selectNodesSlice } from 'features/nodes/store/selectors';
57
import { isBatchNode, isInvocationNode } from 'features/nodes/types/invocation';
68
import { buildNodesGraph } from 'features/nodes/util/graph/buildNodesGraph';
79
import { resolveBatchValue } from 'features/nodes/util/node/resolveBatchValue';
810
import { buildWorkflowWithValidation } from 'features/nodes/util/workflow/buildWorkflow';
911
import { groupBy } from 'lodash-es';
12+
import { serializeError } from 'serialize-error';
1013
import { enqueueMutationFixedCacheKeyOptions, queueApi } from 'services/api/endpoints/queue';
1114
import type { Batch, BatchConfig } from 'services/api/types';
1215

16+
const log = logger('generation');
17+
1318
export const addEnqueueRequestedNodes = (startAppListening: AppStartListening) => {
1419
startAppListening({
1520
predicate: (action): action is ReturnType<typeof enqueueRequested> =>
@@ -101,6 +106,9 @@ export const addEnqueueRequestedNodes = (startAppListening: AppStartListening) =
101106
const req = dispatch(queueApi.endpoints.enqueueBatch.initiate(batchConfig, enqueueMutationFixedCacheKeyOptions));
102107
try {
103108
await req.unwrap();
109+
log.debug(parseify({ batchConfig }), 'Enqueued batch');
110+
} catch (error) {
111+
log.error({ error: serializeError(error) }, 'Failed to enqueue batch');
104112
} finally {
105113
req.reset();
106114
}

invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/enqueueRequestedUpscale.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
import { logger } from 'app/logging/logger';
12
import { enqueueRequested } from 'app/store/actions';
23
import type { AppStartListening } from 'app/store/middleware/listenerMiddleware';
4+
import { parseify } from 'common/util/serialize';
35
import { prepareLinearUIBatch } from 'features/nodes/util/graph/buildLinearBatchConfig';
46
import { buildMultidiffusionUpscaleGraph } from 'features/nodes/util/graph/buildMultidiffusionUpscaleGraph';
7+
import { serializeError } from 'serialize-error';
58
import { enqueueMutationFixedCacheKeyOptions, queueApi } from 'services/api/endpoints/queue';
69

10+
const log = logger('generation');
11+
712
export const addEnqueueRequestedUpscale = (startAppListening: AppStartListening) => {
813
startAppListening({
914
predicate: (action): action is ReturnType<typeof enqueueRequested> =>
@@ -19,6 +24,9 @@ export const addEnqueueRequestedUpscale = (startAppListening: AppStartListening)
1924
const req = dispatch(queueApi.endpoints.enqueueBatch.initiate(batchConfig, enqueueMutationFixedCacheKeyOptions));
2025
try {
2126
await req.unwrap();
27+
log.debug(parseify({ batchConfig }), 'Enqueued batch');
28+
} catch (error) {
29+
log.error({ error: serializeError(error) }, 'Failed to enqueue batch');
2230
} finally {
2331
req.reset();
2432
}

0 commit comments

Comments
 (0)