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)
This commit is contained in:
Marie
2025-11-05 18:58:35 +01:00
committed by GitHub
parent abde3c04ac
commit 982964efbf
2 changed files with 21 additions and 6 deletions
@@ -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),
});
}
}
})();
}, [
@@ -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,