Prevent table columns to be too narrow#16542
Conversation
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
| visibleRecordFields: visibleRecordFields.map((field) => ({ | ||
| ...field, | ||
| size: Math.max(field.size, RECORD_TABLE_COLUMN_MIN_WIDTH), | ||
| })), |
There was a problem hiding this comment.
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
|
Hey @charlesBochet! After you've done the QA of your Pull Request, you can mark it as done here. Thank you! |
|
🚀 Preview Environment Ready! Your preview environment is available at: http://bore.pub:62474 This environment will automatically shut down when the PR is closed or after 5 hours. |
😬
