Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { RecordTableContextProvider as RecordTableContextInternalProvider } from
import { useObjectPermissionsForObject } from '@/object-record/hooks/useObjectPermissionsForObject';
import { visibleRecordFieldsComponentSelector } from '@/object-record/record-field/states/visibleRecordFieldsComponentSelector';
import { recordIndexOpenRecordInState } from '@/object-record/record-index/states/recordIndexOpenRecordInState';
import { RECORD_TABLE_COLUMN_MIN_WIDTH } from '@/object-record/record-table/constants/RecordTableColumnMinWidth';
import { useRecoilComponentValue } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValue';
import { ViewOpenRecordInType } from '@/views/types/ViewOpenRecordInType';
import { useRecoilValue } from 'recoil';
Expand Down Expand Up @@ -52,7 +53,10 @@ export const RecordTableContextProvider = ({
recordTableId,
objectNameSingular,
objectPermissions,
visibleRecordFields,
visibleRecordFields: visibleRecordFields.map((field) => ({
...field,
size: Math.max(field.size, RECORD_TABLE_COLUMN_MIN_WIDTH),
})),
Comment on lines +56 to +59
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: The use of Math.max(field.size, ...) can result in NaN for column width calculations because field.size can be undefined at runtime, breaking the table layout.
Severity: HIGH | Confidence: High

🔍 Detailed Analysis

The code calculates column width using Math.max(field.size, RECORD_TABLE_COLUMN_MIN_WIDTH). Although the type definition for field.size is number, evidence from other parts of the codebase suggests it can be undefined at runtime. When field.size is undefined, Math.max returns NaN. This NaN value is then used in column width calculations, which will break the table layout and rendering. This is a silent failure that can be difficult to debug.

💡 Suggested Fix

Provide a default value for field.size before passing it to Math.max to handle cases where it might be undefined. For example, use the nullish coalescing operator: Math.max(field.size ?? 0, RECORD_TABLE_COLUMN_MIN_WIDTH).

🤖 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/RecordTableContextProvider.tsx#L56-L59

Potential issue: The code calculates column width using `Math.max(field.size,
RECORD_TABLE_COLUMN_MIN_WIDTH)`. Although the type definition for `field.size` is
`number`, evidence from other parts of the codebase suggests it can be `undefined` at
runtime. When `field.size` is `undefined`, `Math.max` returns `NaN`. This `NaN` value is
then used in column width calculations, which will break the table layout and rendering.
This is a silent failure that can be difficult to debug.

Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 7459818

onRecordIdentifierClick,
triggerEvent,
}}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const VIEW_FIELD_MIN_SIZE = 104;
Loading