Skip to content

Commit cd0f898

Browse files
authored
fix(ui): Handle null/undefined span.description safely (#1239)
## Summary Fix runtime error when calling `.trim()` on non-string `span.description` values. ## Root Cause The `Span.description` property is typed as `string | null | undefined`. The previous code used `String(span?.description).trim()` which converts: - `null` → `"null"` (literal string) - `undefined` → `"undefined"` (literal string) These incorrect values passed through the `.delete("")` cleanup and appeared as valid queries/resources. ## Fix Use nullish coalescing (`??`) to return an empty string for `null`/`undefined`, which the existing cleanup handles correctly: ```typescript // Before String(span?.description).trim() // After (span.description ?? "").trim() ``` Fixes SPOTLIGHT-ELECTRON-4V
1 parent b621b56 commit cd0f898

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

packages/spotlight/src/ui/telemetry/components/insights/Queries.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const Queries = () => {
5151
const compareQueryInfo = COMPARATORS[sort.active] || COMPARATORS[QUERIES_SORT_KEYS.totalTime];
5252
const spans = allSpans;
5353
const onlyDBSpans = spans.filter((span: Span) => DB_SPAN_REGEX.test(span.op || ""));
54-
const uniqueSpansSet = new Set(onlyDBSpans.map(span => String(span?.description).trim()));
54+
const uniqueSpansSet = new Set(onlyDBSpans.map(span => (span.description ?? "").trim()));
5555
// Clear out empty ones (they collapse as a single empty string since this is a set)
5656
uniqueSpansSet.delete("");
5757
return [...uniqueSpansSet]

packages/spotlight/src/ui/telemetry/components/insights/Resources.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const Resources = () => {
7373

7474
const resources = useMemo(() => {
7575
const filteredResourceSpans = getResourceSpans(allSpans, { regex: /resource\.[A-Za-z]+/ });
76-
const uniqueResourceDescriptionsSet = new Set(filteredResourceSpans.map(span => String(span?.description).trim()));
76+
const uniqueResourceDescriptionsSet = new Set(filteredResourceSpans.map(span => (span.description ?? "").trim()));
7777
// Clear out empty ones (they collapse as a single empty string since this is a set)
7878
uniqueResourceDescriptionsSet.delete("");
7979
const uniqueResourceDescriptions: string[] = [...uniqueResourceDescriptionsSet];

0 commit comments

Comments
 (0)