Add back first column shrink on mobile#16244
Conversation
| if (shouldCompactRecordTableFirstColumn) { | ||
| updateRecordTableCSSVariable( | ||
| getRecordTableColumnFieldWidthCSSVariableName(0), | ||
| `${RECORD_TABLE_LABEL_IDENTIFIER_COLUMN_WIDTH_ON_MOBILE}px`, | ||
| ); | ||
| } else { | ||
| updateRecordTableCSSVariable( | ||
| getRecordTableColumnFieldWidthCSSVariableName(0), | ||
| `${visibleRecordFields[0].size}px`, | ||
| ); | ||
| } |
There was a problem hiding this comment.
Bug: visibleRecordFields[0].size is accessed without an empty array check, leading to a crash.
Severity: CRITICAL | Confidence: High
🔍 Detailed Analysis
The code unconditionally accesses visibleRecordFields[0].size in the else branch (lines 85-95) without checking if the visibleRecordFields array is empty. If visibleRecordFields is empty and shouldCompactRecordTableFirstColumn is false, this will result in a TypeError: Cannot read property 'size' of undefined, causing an application crash.
💡 Suggested Fix
Add a guard else if (visibleRecordFields[0]) before accessing visibleRecordFields[0].size to prevent errors when the array is empty.
🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location:
packages/twenty-front/src/modules/object-record/record-table/components/RecordTableColumnWidthEffect.tsx#L85-L95
Potential issue: The code unconditionally accesses `visibleRecordFields[0].size` in the
`else` branch (lines 85-95) without checking if the `visibleRecordFields` array is
empty. If `visibleRecordFields` is empty and `shouldCompactRecordTableFirstColumn` is
false, this will result in a `TypeError: Cannot read property 'size' of undefined`,
causing an application crash.
Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 4806745
Greptile OverviewGreptile SummaryImplements dynamic first column compaction on mobile when horizontally scrolled, replacing static CSS media queries with recoil state management.
Confidence Score: 4/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant User
participant ScrollEffect as RecordTableScrollAndZIndexEffect
participant CompactState as shouldCompactRecordTableFirstColumnComponentState
participant LabelState as shouldCompactRecordIndexLabelIdentifierComponentState
participant WidthEffect as RecordTableColumnWidthEffect
participant CSS as CSS Variables
participant ColumnHead as RecordTableColumnHead
participant ChipField as ChipFieldDisplay
Note over User,ChipField: Initial Load (Mobile)
User->>ScrollEffect: Page loads on mobile
ScrollEffect->>CompactState: State = false (not scrolled)
ScrollEffect->>LabelState: State = false (not scrolled)
WidthEffect->>CSS: Set first column to full width
ColumnHead->>CompactState: Read state
ColumnHead->>ColumnHead: Show title (not compact)
ChipField->>LabelState: Read state
ChipField->>ChipField: Show label (not compact)
Note over User,ChipField: User Scrolls Horizontally
User->>ScrollEffect: Scrolls table horizontally
ScrollEffect->>ScrollEffect: Detect scrollLeft > 0
ScrollEffect->>CompactState: Set state = true
ScrollEffect->>LabelState: Set state = true
Note over WidthEffect,CSS: Width Effect Reacts to State Change
WidthEffect->>CompactState: Read state (true)
WidthEffect->>WidthEffect: Calculate with compacted first column (38px)
WidthEffect->>CSS: Update first column width to 38px
WidthEffect->>CSS: Update last column width
WidthEffect->>CSS: Update virtualization body width
Note over ColumnHead,ChipField: Components React to State Change
ColumnHead->>CompactState: Read state (true)
ColumnHead->>ColumnHead: Hide title (compact mode)
ChipField->>LabelState: Read state (true)
ChipField->>ChipField: Hide label (compact mode)
Note over User,ChipField: User Scrolls Back to Start
User->>ScrollEffect: Scrolls back (scrollLeft = 0)
ScrollEffect->>ScrollEffect: Detect scrollLeft = 0
ScrollEffect->>CompactState: Set state = false
ScrollEffect->>LabelState: Set state = false
WidthEffect->>CSS: Restore first column to original width
ColumnHead->>ColumnHead: Show title again
ChipField->>ChipField: Show label again
|
| isMobile, | ||
| setShouldCompactRecordTableFirstColumn, | ||
| setShouldCompactRecordIndexLabelIdentifier, | ||
| visibleRecordFields, |
There was a problem hiding this comment.
logic: visibleRecordFields is included in the dependency array but not used in the effect, which will cause the scroll event listener to be re-registered whenever fields change
| visibleRecordFields, | |
| visibleRecordFields, |
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/twenty-front/src/modules/object-record/record-table/components/RecordTableScrollAndZIndexEffect.tsx
Line: 101:101
Comment:
**logic:** `visibleRecordFields` is included in the dependency array but not used in the effect, which will cause the scroll event listener to be re-registered whenever fields change
```suggestion
visibleRecordFields,
```
How can I resolve this? If you propose a fix, please make it concise.|
🚀 Preview Environment Ready! Your preview environment is available at: http://bore.pub:60669 This environment will automatically shut down when the PR is closed or after 5 hours. |
a7e7d9f to
93d43f9
Compare
| isMobile, | ||
| setShouldCompactRecordTableFirstColumn, | ||
| setShouldCompactRecordIndexLabelIdentifier, | ||
| visibleRecordFields, |
|
Hey @lucasbordeau! After you've done the QA of your Pull Request, you can mark it as done here. Thank you! |
This PR fixes twentyhq#14829 I created two states because one was needed for the table and the other for the ChipFieldDisplay, which can appear anywhere. The states tell if the first column and the ChipFieldDisplay should be shrinked. I also removed the usage of `useRecordTableLastColumnWidthToFill` to avoid unnecessary re-renders of the whole table on scroll. ## Before https://github.com/user-attachments/assets/8b6886b3-8976-41c2-9937-5d7ea396ec56 ## After https://github.com/user-attachments/assets/dc3b5ff9-59c4-4954-a973-57f6edc2508e
This PR fixes #14829
I created two states because one was needed for the table and the other for the ChipFieldDisplay, which can appear anywhere.
The states tell if the first column and the ChipFieldDisplay should be shrinked.
I also removed the usage of
useRecordTableLastColumnWidthToFillto avoid unnecessary re-renders of the whole table on scroll.Before
Enregistrement.de.l.ecran.2025-12-02.a.17.22.23.mov
After
Enregistrement.de.l.ecran.2025-12-02.a.17.22.39.mov