Compare commits

...
Author SHA1 Message Date
Sonarly Claude Code 5cc6696960 applyDiff crashes when cached WorkflowVersion lacks steps field
https://sonarly.com/issue/8672?type=bug

The workflow step creation flow applies server-computed diffs to the Apollo-cached WorkflowVersion, but the cached record may have null/undefined `steps` when the cache contains only partial data, causing `applyDiff` to throw when traversing the diff path.

Fix: The fix adds a guard check for `cachedRecord.steps` and `cachedRecord.trigger` being defined before calling `applyDiff`. When these fields are missing from the partial Apollo cache entry (which can happen when the `WorkflowVersion` was cached via a listing query that only fetches `id`, `status`, `name`, `createdAt`), `applyDiff` would crash trying to traverse a null/undefined value.

By returning early when `steps` or `trigger` are not defined, we skip the optimistic cache update for partially-cached records. The data will be refetched from the server as a natural consequence of the mutation completing, so the UI will still eventually reflect the correct state — just without the immediate optimistic update.

```typescript file=packages/twenty-front/src/modules/workflow/workflow-steps/hooks/useUpdateWorkflowVersionCache.ts lines=44-46
if (!isDefined(cachedRecord.steps) || !isDefined(cachedRecord.trigger)) {
  return;
}
```

This is consistent with the existing pattern in the same function (returning early when `cachedRecord` itself is undefined at line 40-42), and uses the already-imported `isDefined` utility from `twenty-shared/utils`.
2026-03-04 11:22:51 +00:00
@@ -41,6 +41,10 @@ export const useUpdateWorkflowVersionCache = () => {
return;
}
if (!isDefined(cachedRecord.steps) || !isDefined(cachedRecord.trigger)) {
return;
}
const { triggerDiff, stepsDiff } = workflowVersionStepChanges;
const newCachedRecord = {