From 85ae7084abac6c100c18614edfd5055a7d791b54 Mon Sep 17 00:00:00 2001 From: Paul Rastoin <45004772+prastoin@users.noreply.github.com> Date: Wed, 29 Jan 2025 17:11:36 +0100 Subject: [PATCH] [FiX] Optimistic cache useUpdateOneRecord (#9913) # Introduction ~~this could be cool for the updateRecordFromCache to return the updated record, so we could consume its return value more explicitly such as `updatedRecordValue`~~ In fact this is nitpick as it would really be the same than returning the received params ## Fixes duplicated optimistic cache upsert We were before comparing the previously `cachedRecord` which is now, not the latest as the optimistic is (should) be working successfully since https://github.com/twentyhq/twenty/pull/9881 ## Reproduction 1- Open any Company 2- Attach an Opportunity it should appears only once 3bis- If you revert the last branch commit it will appear duplicated Related to #9580 --- .../src/modules/object-record/hooks/useUpdateOneRecord.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/twenty-front/src/modules/object-record/hooks/useUpdateOneRecord.ts b/packages/twenty-front/src/modules/object-record/hooks/useUpdateOneRecord.ts index 023b853e0..f5ffd7dc0 100644 --- a/packages/twenty-front/src/modules/object-record/hooks/useUpdateOneRecord.ts +++ b/packages/twenty-front/src/modules/object-record/hooks/useUpdateOneRecord.ts @@ -130,12 +130,12 @@ export const useUpdateOneRecord = < update: (cache, { data }) => { const record = data?.[mutationResponseField]; - if (!record || !cachedRecord) return; + if (!record || !computedOptimisticRecord) return; triggerUpdateRecordOptimisticEffect({ cache, objectMetadataItem, - currentRecord: cachedRecord, + currentRecord: computedOptimisticRecord, updatedRecord: record, objectMetadataItems, });