-
-
Notifications
You must be signed in to change notification settings - Fork 32
fix: add null safety to WebVitals comparators #1238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
ac59ec9 to
3c9b569
Compare
| return updatedEvent as unknown as SentryEventWithPerformanceData; | ||
| }) | ||
| .filter(event => event.measurements["score.total"] != null) |
There was a problem hiding this comment.
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
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.totalafternormalizePerformanceScore()runs. This ensures the comparators never encounter events with missing measurements.Fixes SPOTLIGHT-ELECTRON-4X
Fixes SPOTLIGHT-ELECTRON-4Q