Skip to content

Conversation

@alexgrozav
Copy link
Member

Summary

This pull request introduces a significant refactor to how workflow state is managed in the frontend application. The main change is that the useWorkflowState composable now requires a workflowId parameter and delegates workflow data access and mutation to the new useWorkflowDocumentsStore. This change improves modularity and ensures workflow state is correctly scoped per workflow. The update also touches many test files to align with the new API and updates all internal references from the global workflow store to the workflow-specific data.

Key changes include:

Core Workflow State Refactor:

  • useWorkflowState now takes a workflowId parameter, and internally uses useWorkflowDocumentsStore to manage workflow data instead of the global store. All references to workflow data in useWorkflowState.ts are updated to use the workflow and workflow object from useWorkflowDocumentsStore. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16]

Test and Helper Updates:

Workflow Initialization:

  • The initializeWorkspace function in useCanvasOperations.ts now calls useWorkflowState with the workflow's id, ensuring state is initialized for the correct workflow.

Store Constants:

  • Adds a new WORKFLOW_DOCUMENTS entry to the STORES constants, reflecting the new store for workflow documents.

Related Linear tickets, Github issues, and Community forum posts

https://linear.app/n8n/issue/CAT-2237/create-useworkflowdocuments-store

Review / Merge checklist

  • PR title and summary are descriptive. (conventions)
  • Docs updated or follow-up ticket created.
  • Tests included.
  • PR Labeled with release/backport (if the PR is an urgent fix that needs to be backported)

alexgrozav and others added 3 commits January 29, 2026 13:25
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Make workflowId parameter optional in useWorkflowState for backward compatibility
- Remove computed wrapper in workflowDocuments.store.ts (Pinia auto-unwraps refs)
- Add fallback to use workflows store directly when no workflowId is provided

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Change useWorkflowState(workflowId?: string) to useWorkflowState(workflowId: string)
- Simplify implementation to always use useWorkflowDocumentsStore
- Keep fallback in injectWorkflowState for circular dependency with useWorkflowHelpers
- Update NodeView.vue to compute workflowId before calling useWorkflowState
- Update useCanvasOperations.ts to pass data.id
- Update all test files to pass 'test-workflow-id'

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@alexgrozav alexgrozav self-assigned this Jan 29, 2026
@codecov
Copy link

codecov bot commented Jan 29, 2026

Bundle Report

Changes will increase total bundle size by 40.94MB (100.0%) ⬆️⚠️, exceeding the configured threshold of 5%.

Bundle name Size Change
editor-ui-esm 40.94MB 40.94MB (100%) ⬆️⚠️

@alexgrozav alexgrozav requested a review from r00gm January 29, 2026 12:01
@codecov
Copy link

codecov bot commented Jan 29, 2026

Codecov Report

❌ Patch coverage is 39.13043% with 14 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ditor-ui/src/app/stores/workflowDocuments.store.ts 0.00% 13 Missing ⚠️
packages/frontend/@n8n/stores/src/constants.ts 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@n8n-assistant n8n-assistant bot added the n8n team Authored by the n8n team label Jan 29, 2026
@blacksmith-sh

This comment has been minimized.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 21 files

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="packages/frontend/editor-ui/src/app/composables/useCanvasOperations.test.ts">

<violation number="1" location="packages/frontend/editor-ui/src/app/composables/useCanvasOperations.test.ts:199">
P2: Use the same workflow id as the seeded test data so the workflow state is scoped to the correct document key.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

setActivePinia(pinia);

workflowState = useWorkflowState();
workflowState = useWorkflowState('test-workflow-id');
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Jan 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Use the same workflow id as the seeded test data so the workflow state is scoped to the correct document key.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/frontend/editor-ui/src/app/composables/useCanvasOperations.test.ts, line 199:

<comment>Use the same workflow id as the seeded test data so the workflow state is scoped to the correct document key.</comment>

<file context>
@@ -196,7 +196,7 @@ describe('useCanvasOperations', () => {
 		setActivePinia(pinia);
 
-		workflowState = useWorkflowState();
+		workflowState = useWorkflowState('test-workflow-id');
 		vi.mocked(injectWorkflowState).mockReturnValue(workflowState);
 	});
</file context>
Suggested change
workflowState = useWorkflowState('test-workflow-id');
workflowState = useWorkflowState(workflowId);
Fix with Cubic


const storesCache = new Map<string, ReturnType<typeof createWorkflowDocumentStore>>();

export function useWorkflowDocumentsStore(id: string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it ever removed?

Remove the manual module-level store cache in workflowDocuments.store.ts
which was causing test isolation issues. The cache persisted across tests,
holding stale references to Pinia store instances from previous test runs.

In useWorkflowState.ts, bypass the documents store for now and use the
workflows store directly. The documents store infrastructure remains for
future multi-document support, using Pinia's built-in store deduplication
instead of a manual cache.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 21 files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

n8n team Authored by the n8n team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants