Fixes infinite loop on record data update in command menu (#12072)

This PR fixes the infinite loop that was happening in `RecordShowEffect`
component due to a useEffect on `recordStoreFamilyState` which was
creating a non-deterministic open loop.

The fix was to use a recoilCallback to avoid reading a stale state from
Recoil with `useRecoilValue`, useRecoilCallback always gets the most
fresh data and commits everything before React goes on with rendering,
thus avoiding any stale value in a useEffect.

Fixes https://github.com/twentyhq/twenty/issues/11079
Fixes https://github.com/twentyhq/core-team-issues/issues/957
This commit is contained in:
Lucas Bordeau
2025-05-15 18:26:01 +02:00
committed by GitHub
parent 442f8dbe3c
commit 09d92c9113
7 changed files with 27 additions and 19 deletions

View File

@ -38,7 +38,7 @@ export const RecordShowRightDrawerOpenRecordButton = ({
objectNameSingular,
recordId,
}: RecordShowRightDrawerOpenRecordButtonProps) => {
const record = useRecoilValue<ObjectRecord | null>(
const record = useRecoilValue<ObjectRecord | null | undefined>(
recordStoreFamilyState(recordId),
);
const { closeCommandMenu } = useCommandMenu();