From 982964efbfafb7db579a58171002a9b71a4e6877 Mon Sep 17 00:00:00 2001 From: Marie <51697796+ijreilly@users.noreply.github.com> Date: Wed, 5 Nov 2025 18:58:35 +0100 Subject: [PATCH] Fix scroll to start when resize or move around columns (#15655) Fixes https://github.com/twentyhq/private-issues/issues/361 There's room for more improvement here - triggerInitialRecordTableDataLoad does a lot of things, should not be triggered so much. actually even RecordTableVirtualizedInitialDataLoadEffect should not be triggered when there's just a metadata field change (if we trust the name initialDataLoad) --- ...ecordTableVirtualizedInitialDataLoadEffect.tsx | 12 +++++++++++- .../hooks/useTriggerInitialRecordTableDataLoad.ts | 15 ++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/packages/twenty-front/src/modules/object-record/record-table/virtualization/components/RecordTableVirtualizedInitialDataLoadEffect.tsx b/packages/twenty-front/src/modules/object-record/record-table/virtualization/components/RecordTableVirtualizedInitialDataLoadEffect.tsx index 804a5ab749..34dcdd4d06 100644 --- a/packages/twenty-front/src/modules/object-record/record-table/virtualization/components/RecordTableVirtualizedInitialDataLoadEffect.tsx +++ b/packages/twenty-front/src/modules/object-record/record-table/virtualization/components/RecordTableVirtualizedInitialDataLoadEffect.tsx @@ -13,6 +13,7 @@ import { isFetchingMoreRecordsFamilyState } from '@/object-record/states/isFetch import { useRecoilComponentState } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentState'; import { useRecoilComponentValue } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValue'; import { useGetCurrentViewOnly } from '@/views/hooks/useGetCurrentViewOnly'; +import isEmpty from 'lodash.isempty'; import { useEffect } from 'react'; // TODO: see if we can merge the initial and load more processes, to have only one load at scroll index effect @@ -75,7 +76,16 @@ export const RecordTableVirtualizedInitialDataLoadEffect = () => { ) { setLastContextStoreVisibleRecordFields(visibleRecordFields); - await triggerInitialRecordTableDataLoad(); + const lastFields = lastContextStoreVisibleRecordFields || []; + const currentFields = visibleRecordFields || []; + + const shouldRefetchData = currentFields.length > lastFields.length; + + if (shouldRefetchData) { + await triggerInitialRecordTableDataLoad({ + shouldScrollToStart: isEmpty(lastFields), + }); + } } })(); }, [ diff --git a/packages/twenty-front/src/modules/object-record/record-table/virtualization/hooks/useTriggerInitialRecordTableDataLoad.ts b/packages/twenty-front/src/modules/object-record/record-table/virtualization/hooks/useTriggerInitialRecordTableDataLoad.ts index d4aaf6f704..f012b595b0 100644 --- a/packages/twenty-front/src/modules/object-record/record-table/virtualization/hooks/useTriggerInitialRecordTableDataLoad.ts +++ b/packages/twenty-front/src/modules/object-record/record-table/virtualization/hooks/useTriggerInitialRecordTableDataLoad.ts @@ -104,7 +104,9 @@ export const useTriggerInitialRecordTableDataLoad = () => { const triggerInitialRecordTableDataLoad = useRecoilCallback( ({ snapshot, set }) => - async () => { + async ({ + shouldScrollToStart = true, + }: { shouldScrollToStart?: boolean } = {}) => { const isInitializingVirtualTableDataLoading = getSnapshotValue( snapshot, isInitializingVirtualTableDataLoadingCallbackState, @@ -189,11 +191,14 @@ export const useTriggerInitialRecordTableDataLoad = () => { setIsRecordTableScrolledHorizontally(false); setIsRecordTableScrolledVertically(false); + resetTableFocuses(); - scrollTableToPosition({ - horizontalScrollInPx: 0, - verticalScrollInPx: 0, - }); + if (shouldScrollToStart) { + scrollTableToPosition({ + horizontalScrollInPx: 0, + verticalScrollInPx: 0, + }); + } }, [ isInitializingVirtualTableDataLoadingCallbackState,