From be4b466234a38c8ef579d2705788e88613b742ce Mon Sep 17 00:00:00 2001 From: Thomas Trompette Date: Thu, 7 May 2026 09:57:10 +0200 Subject: [PATCH] Remove broken total count from workflow version (#20324) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Problem Opening a workflow run with a form step in the side panel, closing the form and reopening it crashes the app: `` blows up on `workflow.versions.find` because `versions` is `null` in the Apollo cache. ## Root cause `useWorkflowVersion` was selecting: ```ts workflow: { id, name, statuses, versions: { totalCount: true } } ``` Twenty's GraphQL field generator doesn't support connection-level scalars — { totalCount: true } is interpreted as fields on the inner WorkflowVersion node, gets filtered out, and the query collapses to: versions { edges { node { __typename } } } The server returns versions: null for that empty-node selection. Why now The selection has always been wrong, but two recent changes made it consistently surface: Apollo Client v4 upgrade (#18584): stricter normalized writes, null always wins. #20242: WorkflowRunSSESubscribeEffect in the form filler keeps SSE flowing, which re-fires useWorkflowVersion more often, making the bad query consistently the last writer. --- .../src/modules/workflow/hooks/useWorkflowVersion.ts | 12 ++---------- .../workflow/hooks/useWorkflowWithCurrentVersion.ts | 2 +- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/packages/twenty-front/src/modules/workflow/hooks/useWorkflowVersion.ts b/packages/twenty-front/src/modules/workflow/hooks/useWorkflowVersion.ts index 2e4b803bac..d4edf4d7f7 100644 --- a/packages/twenty-front/src/modules/workflow/hooks/useWorkflowVersion.ts +++ b/packages/twenty-front/src/modules/workflow/hooks/useWorkflowVersion.ts @@ -1,14 +1,10 @@ -import { CoreObjectNameSingular } from 'twenty-shared/types'; import { useFindOneRecord } from '@/object-record/hooks/useFindOneRecord'; import { type Workflow, type WorkflowVersion } from '@/workflow/types/Workflow'; +import { CoreObjectNameSingular } from 'twenty-shared/types'; export const useWorkflowVersion = (workflowVersionId?: string) => { const { record: workflowVersion } = useFindOneRecord< - WorkflowVersion & { - workflow: Omit & { - versions: Array<{ __typename: string }>; - }; - } + WorkflowVersion & { workflow: Pick } >({ objectNameSingular: CoreObjectNameSingular.WorkflowVersion, objectRecordId: workflowVersionId, @@ -24,10 +20,6 @@ export const useWorkflowVersion = (workflowVersionId?: string) => { workflow: { id: true, name: true, - statuses: true, - versions: { - totalCount: true, - }, }, }, skip: !workflowVersionId, diff --git a/packages/twenty-front/src/modules/workflow/hooks/useWorkflowWithCurrentVersion.ts b/packages/twenty-front/src/modules/workflow/hooks/useWorkflowWithCurrentVersion.ts index 5c3397d19a..203d8ba032 100644 --- a/packages/twenty-front/src/modules/workflow/hooks/useWorkflowWithCurrentVersion.ts +++ b/packages/twenty-front/src/modules/workflow/hooks/useWorkflowWithCurrentVersion.ts @@ -1,6 +1,5 @@ import { useEffect } from 'react'; -import { CoreObjectNameSingular } from 'twenty-shared/types'; import { useFindOneRecord } from '@/object-record/hooks/useFindOneRecord'; import { useAtomFamilyStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomFamilyStateValue'; import { useSetAtomFamilyState } from '@/ui/utilities/state/jotai/hooks/useSetAtomFamilyState'; @@ -10,6 +9,7 @@ import { type WorkflowVersion, type WorkflowWithCurrentVersion, } from '@/workflow/types/Workflow'; +import { CoreObjectNameSingular } from 'twenty-shared/types'; import { isDefined } from 'twenty-shared/utils'; type WorkflowWithAllVersions = Omit & {