Skip to content

Fix scroll to start when resize or move around columns#15655

Merged
ijreilly merged 2 commits intomainfrom
fix--scroll-start-when-resize
Nov 5, 2025
Merged

Fix scroll to start when resize or move around columns#15655
ijreilly merged 2 commits intomainfrom
fix--scroll-start-when-resize

Conversation

@ijreilly
Copy link
Copy Markdown
Contributor

@ijreilly ijreilly commented Nov 5, 2025

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)


if (shouldRefetchData) {
await triggerInitialRecordTableDataLoad({
shouldScrollToStart: isEmpty(lastFields),
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isEmpty(lastFields) helps determining if it is an initial load or not

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Greptile Overview

Greptile Summary

Added conditional scroll behavior to prevent table from scrolling to the start when columns are resized or moved. The fix introduces a shouldScrollToStart parameter that only scrolls when there were no previous fields loaded.

Key changes:

  • Only refetches data when column count increases (currentFields.length > lastFields.length)
  • Only scrolls to start position when transitioning from empty to non-empty field list (isEmpty(lastFields))
  • Always resets table focus state regardless of scroll behavior

Issue found:

  • The shouldRefetchData logic only checks if columns were added (>), not if they were removed or reordered. This means column removals and reorderings won't trigger a refetch, which could lead to data display issues.

Confidence Score: 3/5

  • This PR partially fixes the scroll issue but introduces a logic bug that prevents proper handling of column removal and reordering
  • The fix addresses the reported scroll-to-start issue when columns are resized, but the shouldRefetchData logic only handles column additions (>), not removals or reorderings. This creates scenarios where the table won't refetch data when columns are removed or reordered, potentially causing display inconsistencies.
  • RecordTableVirtualizedInitialDataLoadEffect.tsx needs correction to the shouldRefetchData condition on line 82

Important Files Changed

File Analysis

Filename Score Overview
packages/twenty-front/src/modules/object-record/record-table/virtualization/components/RecordTableVirtualizedInitialDataLoadEffect.tsx 3/5 Added conditional logic to prevent unnecessary data refetches and scrolling when only column order changes. Only refetches when columns are added, and only scrolls to start when there were no previous fields.

Sequence Diagram

sequenceDiagram
    participant User
    participant Effect as RecordTableVirtualizedInitialDataLoadEffect
    participant Hook as useTriggerInitialRecordTableDataLoad
    participant Table as Record Table

    User->>Table: Resize or move column
    Table->>Effect: visibleRecordFields changes
    Effect->>Effect: Compare lastFields vs currentFields
    
    alt currentFields.length > lastFields.length
        Effect->>Effect: shouldRefetchData = true
        alt isEmpty(lastFields)
            Effect->>Hook: triggerInitialRecordTableDataLoad({shouldScrollToStart: true})
            Hook->>Hook: resetTableFocuses()
            Hook->>Hook: Load data
            Hook->>Table: scrollTableToPosition({0, 0})
        else lastFields not empty
            Effect->>Hook: triggerInitialRecordTableDataLoad({shouldScrollToStart: false})
            Hook->>Hook: resetTableFocuses()
            Hook->>Hook: Load data
            Note over Hook,Table: No scroll - preserves position
        end
    else currentFields.length <= lastFields.length
        Note over Effect: shouldRefetchData = false<br/>No refetch, no scroll
    end
Loading

2 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

const lastFields = lastContextStoreVisibleRecordFields || [];
const currentFields = visibleRecordFields || [];

const shouldRefetchData = currentFields.length > lastFields.length;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: this logic will not handle column removal or reordering correctly. When columns are removed, currentFields.length will be less than or equal to lastFields.length, so shouldRefetchData will be false and data won't be refetched. Column reordering would also be skipped since lengths are equal.

Suggested change
const shouldRefetchData = currentFields.length > lastFields.length;
const shouldRefetchData = currentFields.length !== lastFields.length;
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/twenty-front/src/modules/object-record/record-table/virtualization/components/RecordTableVirtualizedInitialDataLoadEffect.tsx
Line: 82:82

Comment:
**logic:** this logic will not handle column removal or reordering correctly. When columns are removed, `currentFields.length` will be less than or equal to `lastFields.length`, so `shouldRefetchData` will be false and data won't be refetched. Column reordering would also be skipped since lengths are equal.

```suggestion
        const shouldRefetchData = currentFields.length !== lastFields.length;
```

How can I resolve this? If you propose a fix, please make it concise.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Nov 5, 2025

🚀 Preview Environment Ready!

Your preview environment is available at: http://bore.pub:21743

This environment will automatically shut down when the PR is closed or after 5 hours.

Copy link
Copy Markdown
Contributor

@lucasbordeau lucasbordeau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ijreilly ijreilly merged commit 982964e into main Nov 5, 2025
58 of 59 checks passed
@ijreilly ijreilly deleted the fix--scroll-start-when-resize branch November 5, 2025 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants