Compare commits

...
Author SHA1 Message Date
Sonarly Claude Code 71d132238f fix: remove refetchQueries from deleteWorkflowVersionStep to prevent cache/diff mismatch
https://sonarly.com/issue/18350?type=bug

Deleting a workflow step crashes the frontend because the Apollo cache is updated twice: once by `refetchQueries` and then again by `applyDiff`, which fails because the diff references step indices that no longer exist in the already-updated cache.

Fix: Removed `refetchQueries` and `awaitRefetchQueries` from the `useDeleteWorkflowVersionStep` hook, along with the now-unused `useFindOneRecordQuery` and `CoreObjectNameSingular` imports.

**Why**: The hook was using two conflicting cache update mechanisms:
1. `awaitRefetchQueries: true` with `refetchQueries` — which fetches the post-deletion state from the server and writes it to the Apollo cache
2. `updateWorkflowVersionCache` — which applies a server-computed diff (against the pre-deletion state) to the Apollo cache

Because `awaitRefetchQueries` completes before `updateWorkflowVersionCache` runs, the cache already contains the post-deletion state when the diff is applied. The diff references array indices from the pre-deletion state (e.g., `steps[14]`), which no longer exist, causing `applyDiff` to throw "Expected object or array, got undefined".

The fix removes the refetch, leaving only the diff-based cache update — matching the pattern used by `useCreateWorkflowVersionStep` and `useDuplicateWorkflowVersionStep`, which both work correctly.
2026-03-25 15:08:41 +00:00
@@ -1,6 +1,4 @@
import { useApolloCoreClient } from '@/object-metadata/hooks/useApolloCoreClient';
import { CoreObjectNameSingular } from 'twenty-shared/types';
import { useFindOneRecordQuery } from '@/object-record/hooks/useFindOneRecordQuery';
import { DELETE_WORKFLOW_VERSION_STEP } from '@/workflow/graphql/mutations/deleteWorkflowVersionStep';
import { useUpdateWorkflowVersionCache } from '@/workflow/workflow-steps/hooks/useUpdateWorkflowVersionCache';
import { useMutation } from '@apollo/client/react';
@@ -15,11 +13,6 @@ export const useDeleteWorkflowVersionStep = () => {
const { updateWorkflowVersionCache } = useUpdateWorkflowVersionCache();
const { findOneRecordQuery: findOneWorkflowVersionQuery } =
useFindOneRecordQuery({
objectNameSingular: CoreObjectNameSingular.WorkflowVersion,
});
const [mutate] = useMutation<
DeleteWorkflowVersionStepMutation,
DeleteWorkflowVersionStepMutationVariables
@@ -32,13 +25,6 @@ export const useDeleteWorkflowVersionStep = () => {
) => {
const result = await mutate({
variables: { input },
awaitRefetchQueries: true,
refetchQueries: [
{
query: findOneWorkflowVersionQuery,
variables: { objectRecordId: input.workflowVersionId },
},
],
});
const workflowVersionStepChanges = result?.data?.deleteWorkflowVersionStep;