Skip to content

Commit 47f7a3e

Browse files
committed
fix: Improve null safety in buildSchemaTree by adding optional chaining for field UIDs
1 parent 0271527 commit 47f7a3e

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

api/src/utils/content-type-creator.utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ export function buildSchemaTree(fields: any[], parentUid = '', parentType = '',
279279
});
280280

281281
return directChildren.map(field => {
282-
const uid = getLastSegmentNew(field.contentstackFieldUid, '.');
282+
const uid = getLastSegmentNew(field?.contentstackFieldUid, '.');
283283
const displayName = field?.display_name || getLastSegmentNew(field?.contentstackField || '', '>').trim();
284284

285285
// Base field structure
@@ -300,14 +300,14 @@ export function buildSchemaTree(fields: any[], parentUid = '', parentType = '',
300300
if (!fUid) return false;
301301

302302
// Check if field starts with current fieldUid and is exactly one level deeper
303-
if (fieldUid && fUid.startsWith(fieldUid + '.')) {
303+
if (fieldUid && fUid?.startsWith(fieldUid + '.')) {
304304
const remainder = fUid?.substring(fieldUid.length + 1);
305305
return remainder && !remainder?.includes('.');
306306
}
307307

308308
// Check if field starts with oldFieldtUid and is exactly one level deeper
309-
if (oldFieldUid && fUid.startsWith(oldFieldUid + '.')) {
310-
const remainder = fUid.substring(oldFieldUid.length + 1);
309+
if (oldFieldUid && fUid?.startsWith(oldFieldUid + '.')) {
310+
const remainder = fUid?.substring(oldFieldUid.length + 1);
311311
return remainder && !remainder?.includes('.');
312312
}
313313

0 commit comments

Comments
 (0)