Skip to content

Conversation

@BYK
Copy link
Member

@BYK BYK commented Jan 7, 2026

Summary

Adds a null safety filter to the WebVitals component to prevent TypeError: Cannot read properties of undefined (reading 'value') when sorting events that don't have score measurements after normalization.

Changes

Filters out events without a valid score.total after normalizePerformanceScore() runs. This ensures the comparators never encounter events with missing measurements.

Fixes SPOTLIGHT-ELECTRON-4X
Fixes SPOTLIGHT-ELECTRON-4Q

@BYK BYK deployed to Preview January 7, 2026 23:55 — with GitHub Actions Active
@vercel
Copy link

vercel bot commented Jan 7, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Review Updated (UTC)
spotlightjs Skipped Skipped Jan 8, 2026 0:04am

@BYK BYK force-pushed the fix/webvitals-comparator-null-safety branch from ac59ec9 to 3c9b569 Compare January 8, 2026 00:04
@BYK BYK deployed to Preview January 8, 2026 00:04 — with GitHub Actions Active
@BYK BYK marked this pull request as ready for review January 8, 2026 00:05
@BYK BYK enabled auto-merge (squash) January 8, 2026 00:05
@BYK BYK merged commit b621b56 into main Jan 8, 2026
20 checks passed
@BYK BYK deleted the fix/webvitals-comparator-null-safety branch January 8, 2026 00:10
Comment on lines 56 to +58
return updatedEvent as unknown as SentryEventWithPerformanceData;
})
.filter(event => event.measurements["score.total"] != null)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Direct navigation to a non-pageload event detail page in WebVitalsDetail.tsx causes a crash due to unguarded access to score measurements which are not populated.
Severity: HIGH | Confidence: High

🔍 Detailed Analysis

The WebVitalsDetail.tsx component can crash if a user navigates directly to a detail page for an event that is not a 'pageload' event or lacks a measurements object. The list view in index.tsx correctly filters for event?.contexts?.trace?.op === 'pageload', but the detail page does not. When an invalid event is loaded directly via URL, normalizePerformanceScore is called but fails to add the expected score.* measurements. The component then attempts to access properties like measurements['score.fcp'].value, resulting in a TypeError because the score object is undefined.

💡 Suggested Fix

In WebVitalsDetail.tsx, before rendering the details, add checks to ensure that the loaded event is a 'pageload' event and that the necessary measurements and score.* properties exist after normalization. This will prevent the component from attempting to access properties on undefined objects.

🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location:
packages/spotlight/src/ui/telemetry/components/insights/webVitals/index.tsx#L56-L58

Potential issue: The `WebVitalsDetail.tsx` component can crash if a user navigates
directly to a detail page for an event that is not a 'pageload' event or lacks a
`measurements` object. The list view in `index.tsx` correctly filters for
`event?.contexts?.trace?.op === 'pageload'`, but the detail page does not. When an
invalid event is loaded directly via URL, `normalizePerformanceScore` is called but
fails to add the expected `score.*` measurements. The component then attempts to access
properties like `measurements['score.fcp'].value`, resulting in a `TypeError` because
the score object is undefined.

Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 8311977

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants