The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Fix memory crash when creating record in table view (#16984)
Etienne81afc8b9cae9
diff --git a/packages/twenty-front/src/modules/object-record/record-table/virtualization/hooks/useResetVirtualizationBecauseDataChanged.ts b/packages/twenty-front/src/modules/object-record/record-table/virtualization/hooks/useResetVirtualizationBecauseDataChanged.tsindex 162067833e3..e6ed969ac68 100644--- a/packages/twenty-front/src/modules/object-record/record-table/virtualization/hooks/useResetVirtualizationBecauseDataChanged.ts+++ b/packages/twenty-front/src/modules/object-record/record-table/virtualization/hooks/useResetVirtualizationBecauseDataChanged.ts@@ -4,16 +4,9 @@ import { useRecordsFieldVisibleGqlFields } from '@/object-record/record-field/hoimport { useFindManyRecordIndexTableParams } from '@/object-record/record-index/hooks/useFindManyRecordIndexTableParams';import { useTriggerFetchPages } from '@/object-record/record-table/virtualization/hooks/useTriggerFetchPages';-import { dataLoadingStatusByRealIndexComponentFamilyState } from '@/object-record/record-table/virtualization/states/dataLoadingStatusByRealIndexComponentFamilyState';import { dataPagesLoadedComponentState } from '@/object-record/record-table/virtualization/states/dataPagesLoadedComponentState';-import { lastScrollPositionComponentState } from '@/object-record/record-table/virtualization/states/lastScrollPositionComponentState';-import { recordIdByRealIndexComponentFamilyState } from '@/object-record/record-table/virtualization/states/recordIdByRealIndexComponentFamilyState';import { totalNumberOfRecordsToVirtualizeComponentState } from '@/object-record/record-table/virtualization/states/totalNumberOfRecordsToVirtualizeComponentState';-import { getVirtualizationOverscanWindow } from '@/object-record/record-table/virtualization/utils/getVirtualizationOverscanWindow';-import { useScrollWrapperHTMLElement } from '@/ui/utilities/scroll/hooks/useScrollWrapperHTMLElement';import { useRecoilComponentCallbackState } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentCallbackState';-import { useRecoilComponentFamilyCallbackState } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentFamilyCallbackState';-import { getSnapshotValue } from '@/ui/utilities/state/utils/getSnapshotValue';import { useCallback } from 'react';import { useRecoilCallback } from 'recoil';import { sleep } from '~/utils/sleep';@@ -26,7 +19,6 @@ export const useResetVirtualizationBecauseDataChanged = (});const params = useFindManyRecordIndexTableParams(objectNameSingular);- const { scrollWrapperHTMLElement } = useScrollWrapperHTMLElement();// TODO: we could optimize this by using an aggregate or using only id: true in recordGqlFieldsconst recordGqlFields = useRecordsFieldVisibleGqlFields({@@ -49,82 +41,20 @@ export const useResetVirtualizationBecauseDataChanged = (dataPagesLoadedComponentState,);- const lastScrollPositionCallbackState = useRecoilComponentCallbackState(- lastScrollPositionComponentState,- );-- const recordIdByRealIndexCallbackState =- useRecoilComponentFamilyCallbackState(- recordIdByRealIndexComponentFamilyState,- );-- const dataLoadingStatusByRealIndexCallbackState =- useRecoilComponentCallbackState(- dataLoadingStatusByRealIndexComponentFamilyState,- );-const { triggerFetchPagesWithoutDebounce } = useTriggerFetchPages();const resetVirtualization = useRecoilCallback(- ({ set, snapshot }) =>+ ({ set }) =>async () => {const { totalCount } = await findManyRecordsLazy();- const tableScrollWrapperHeight =- scrollWrapperHTMLElement?.clientHeight ?? 0;-- const lastScrollPosition = getSnapshotValue(- snapshot,- lastScrollPositionCallbackState,- );-- const totalNumberOfRecordsToVirtualize =- getSnapshotValue(- snapshot,- totalNumberOfRecordsToVirtualizeCallbackState,- ) ?? 0;-- const {- firstRealIndexInOverscanWindow,- lastRealIndexInOverscanWindow,- } = getVirtualizationOverscanWindow(- lastScrollPosition,- tableScrollWrapperHeight,- totalNumberOfRecordsToVirtualize,- );-- for (let i = 0; i < totalNumberOfRecordsToVirtualize; i++) {- const indexIsInOverscanWindow =- i >= firstRealIndexInOverscanWindow &&- i <= lastRealIndexInOverscanWindow;-- if (!indexIsInOverscanWindow) {- set(- dataLoadingStatusByRealIndexCallbackState({- realIndex: i,- }),- null,- );-- set(- recordIdByRealIndexCallbackState({- realIndex: i,- }),- null,- );- }- }set(dataPagesLoadedCallbackState, []);set(totalNumberOfRecordsToVirtualizeCallbackState, totalCount);},[- findManyRecordsLazy,- scrollWrapperHTMLElement?.clientHeight,- lastScrollPositionCallbackState,- totalNumberOfRecordsToVirtualizeCallbackState,dataPagesLoadedCallbackState,- dataLoadingStatusByRealIndexCallbackState,- recordIdByRealIndexCallbackState,+ totalNumberOfRecordsToVirtualizeCallbackState,+ findManyRecordsLazy,],);