fix: gracefully handle missing identifier chip generator for custom objects
https://sonarly.com/issue/22439?type=bug When a custom object (e.g., "deliverable") is referenced via a relation field, the UI crashes with an unhandled throw if no identifier chip generator exists for that object. The user sees the error on `/objects/projects` page when the table tries to render relation chips. Fix: Restored the graceful fallback in `useRecordChipData` when an identifier chip generator is missing for an object. The commit98e199c01d("Support Full Name as Record Text Identifier") replaced the previous graceful fallback with a hard `throw new Error(...)`. This causes a React crash whenever a custom object's chip generator is missing from the pre-computed map — which can happen when: - A custom object's label identifier field is misconfigured - Metadata store has objects loaded before their fields (localStorage race condition) - A custom object's label identifier field was deleted The fix restores the original pattern: when a chip generator is not found for an object, fall back to `generateDefaultRecordChipData()` which produces a reasonable chip using the record's `name` field. This utility already exists and is used by `useRelationFromManyFieldDisplay` and `useRelationToOneFieldDisplay` for the same purpose. This matches the team's established pattern (see commit6e7d2db58fby Charles Bochet: "Fix From Many relation for deleted notes crashing") where the approach is to gracefully degrade rather than crash when metadata is incomplete.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { PreComputedChipGeneratorsContext } from '@/object-metadata/contexts/PreComputedChipGeneratorsContext';
|
||||
import { generateDefaultRecordChipData } from '@/object-metadata/utils/generateDefaultRecordChipData';
|
||||
import { type RecordChipData } from '@/object-record/record-field/ui/types/RecordChipData';
|
||||
import { type ObjectRecord } from '@/object-record/types/ObjectRecord';
|
||||
import { useContext } from 'react';
|
||||
@@ -22,13 +23,16 @@ export const useRecordChipData = ({
|
||||
const identifierChipGenerator =
|
||||
identifierChipGeneratorPerObject[objectNameSingular];
|
||||
|
||||
if (!isDefined(identifierChipGenerator)) {
|
||||
throw new Error(
|
||||
`No identifier chip generator found for object name singular: ${objectNameSingular}`,
|
||||
);
|
||||
if (isDefined(identifierChipGenerator)) {
|
||||
return {
|
||||
recordChipData: identifierChipGenerator(record),
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
recordChipData: identifierChipGenerator(record),
|
||||
recordChipData: generateDefaultRecordChipData({
|
||||
objectNameSingular,
|
||||
record,
|
||||
}),
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user