Compare commits

...
Author SHA1 Message Date
Sonarly Claude Code dc6c6c16c9 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 commit 98e199c01d ("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 commit 6e7d2db58f by Charles Bochet: "Fix From Many relation for deleted notes crashing") where the approach is to gracefully degrade rather than crash when metadata is incomplete.
2026-04-07 13:29:14 +00:00
@@ -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,
}),
};
};