Fix record title cell crash when field value is not a string (#19109)
https://sonarly.com/issue/29800?type=bug The record title cell crashes with `TypeError: a.trim is not a function` when a custom object's label identifier TEXT field contains a non-string value (e.g., number, boolean) in the record store. Fix: Replaced `!isDefined(fieldValue) || fieldValue.trim() === ''` with `typeof fieldValue !== 'string' || fieldValue.trim() === ''` on the isEmpty check. The `isDefined()` guard only rejects null/undefined, so any defined non-string value (number, boolean, object) passed through and crashed on `.trim()`. The `typeof` check is a proper runtime type narrowing: if fieldValue is not a string, isEmpty is immediately true (rendering the "Untitled" placeholder), and `.trim()` is only ever called on actual strings. Removed the now-unused `isDefined` import from `twenty-shared/utils`. This is a single-line logic change plus import cleanup — no API, prop, or behavioral changes outside the crash path. Non-string field values now gracefully display the empty-state placeholder instead of throwing a TypeError.
This commit is contained in:
+1
-2
@@ -7,7 +7,6 @@ import { useAtomFamilyStateValue } from '@/ui/utilities/state/jotai/hooks/useAto
|
||||
import { styled } from '@linaria/react';
|
||||
import { t } from '@lingui/core/macro';
|
||||
import { useContext } from 'react';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
import { OverflowingTextWithTooltip } from 'twenty-ui/display';
|
||||
import { themeCssVariables } from 'twenty-ui/theme-constants';
|
||||
|
||||
@@ -43,7 +42,7 @@ export const RecordTitleCellSingleTextDisplayMode = ({
|
||||
const recordStore = useAtomFamilyStateValue(recordStoreFamilyState, recordId);
|
||||
|
||||
const fieldValue = recordStore?.[fieldDefinition.metadata.fieldName];
|
||||
const isEmpty = !isDefined(fieldValue) || fieldValue.trim() === '';
|
||||
const isEmpty = typeof fieldValue !== 'string' || fieldValue.trim() === '';
|
||||
|
||||
const { openRecordTitleCell } = useRecordTitleCell();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user