From 3115e9baafe371c33f39a6d33da4cb34486cca3c Mon Sep 17 00:00:00 2001 From: Benjamin Schroth <68321970+schrothbn@users.noreply.github.com> Date: Wed, 20 May 2026 22:13:56 +0200 Subject: [PATCH] fix(editor): Continue manually triggered evaluation runs (#30814) --- .../src/app/composables/useRunWorkflow.test.ts | 16 ++++++++++++++++ .../src/app/composables/useRunWorkflow.ts | 7 +++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/frontend/editor-ui/src/app/composables/useRunWorkflow.test.ts b/packages/frontend/editor-ui/src/app/composables/useRunWorkflow.test.ts index c51ead73644..ca98a16225a 100644 --- a/packages/frontend/editor-ui/src/app/composables/useRunWorkflow.test.ts +++ b/packages/frontend/editor-ui/src/app/composables/useRunWorkflow.test.ts @@ -326,6 +326,22 @@ describe('useRunWorkflow({ router })', () => { ); }); + it('should use the passed-in workflowState when injection is unavailable', async () => { + vi.mocked(injectWorkflowState).mockReturnValue(undefined as unknown as WorkflowState); + + const setActiveExecutionId = vi.spyOn(workflowState, 'setActiveExecutionId'); + const { runWorkflowApi } = useRunWorkflow({ router, workflowState }); + + vi.mocked(pushConnectionStore).isConnected = true; + vi.mocked(workflowsStore).runWorkflow.mockResolvedValue({ + executionId: '123', + waitingForWebhook: false, + }); + + await expect(runWorkflowApi({} as IStartRunData)).resolves.not.toThrow(); + expect(setActiveExecutionId).toHaveBeenCalled(); + }); + it('should successfully run a workflow', async () => { const setActiveExecutionId = vi.spyOn(workflowState, 'setActiveExecutionId'); const { runWorkflowApi } = useRunWorkflow({ router }); diff --git a/packages/frontend/editor-ui/src/app/composables/useRunWorkflow.ts b/packages/frontend/editor-ui/src/app/composables/useRunWorkflow.ts index 94019aeb759..3ccd781163a 100644 --- a/packages/frontend/editor-ui/src/app/composables/useRunWorkflow.ts +++ b/packages/frontend/editor-ui/src/app/composables/useRunWorkflow.ts @@ -55,13 +55,14 @@ import { useCanvasOperations } from './useCanvasOperations'; import { chatEventBus } from '@n8n/chat/event-buses'; import { useAgentRequestStore } from '@n8n/stores/useAgentRequestStore'; import { useWorkflowSaving } from './useWorkflowSaving'; -import { injectWorkflowState } from '@/app/composables/useWorkflowState'; +import { injectWorkflowState, type WorkflowState } from '@/app/composables/useWorkflowState'; import { useDocumentTitle } from './useDocumentTitle'; import { useChat } from '@n8n/chat/composables'; import type { WorkflowObjectAccessors } from '../types'; export function useRunWorkflow(useRunWorkflowOpts: { router: ReturnType; + workflowState?: WorkflowState; }) { const workflowHelpers = useWorkflowHelpers(); const i18n = useI18n(); @@ -75,7 +76,9 @@ export function useRunWorkflow(useRunWorkflowOpts: { const rootStore = useRootStore(); const pushConnectionStore = usePushConnectionStore(); const workflowsStore = useWorkflowsStore(); - const workflowState = injectWorkflowState(); + // `inject()` only resolves inside a setup context; callers from async event + // handlers must pass `workflowState` in. + const workflowState = useRunWorkflowOpts.workflowState ?? injectWorkflowState(); const workflowDocumentStore = injectWorkflowDocumentStore();