Fix infinite loop on table load (#12474)

This was a tough one:
- we should avoid updating lazy findManyRecords function with
onCompleted callback, this is prone to infinite loops
This commit is contained in:
Charles Bochet
2025-06-05 19:37:23 +02:00
committed by GitHub
parent 39d3c6a218
commit 9598a4dda2
2 changed files with 4 additions and 16 deletions

View File

@ -94,8 +94,6 @@ export const useLazyFindManyRecords = <T extends ObjectRecord = ObjectRecord>({
set(hasNextPageFamilyState(queryIdentifier), false); set(hasNextPageFamilyState(queryIdentifier), false);
set(cursorFamilyState(queryIdentifier), ''); set(cursorFamilyState(queryIdentifier), '');
onCompleted?.([]);
return { return {
data: null, data: null,
loading: false, loading: false,
@ -124,7 +122,6 @@ export const useLazyFindManyRecords = <T extends ObjectRecord = ObjectRecord>({
findManyRecords, findManyRecords,
objectMetadataItem.namePlural, objectMetadataItem.namePlural,
queryIdentifier, queryIdentifier,
onCompleted,
], ],
); );

View File

@ -58,8 +58,6 @@ export const RecordTableNoRecordGroupBodyEffect = () => {
lastShowPageRecordIdState, lastShowPageRecordIdState,
); );
const [hasInitialized, setHasInitialized] = useState(false);
const { scrollToPosition } = useScrollToPosition(); const { scrollToPosition } = useScrollToPosition();
useEffect(() => { useEffect(() => {
@ -142,21 +140,14 @@ export const RecordTableNoRecordGroupBodyEffect = () => {
]); ]);
useEffect(() => { useEffect(() => {
setIsRecordTableInitialLoading(false);
if (showAuthModal) { if (showAuthModal) {
setIsRecordTableInitialLoading(false);
return; return;
} }
if (!hasInitialized) { findManyRecords();
findManyRecords(); }, [findManyRecords, setIsRecordTableInitialLoading, showAuthModal]);
setHasInitialized(true);
}
}, [
findManyRecords,
hasInitialized,
setIsRecordTableInitialLoading,
showAuthModal,
]);
return <></>; return <></>;
}; };