From 52ceec528c4e293d92afc6567886b9ee9dcffc7a Mon Sep 17 00:00:00 2001 From: Burak Yigit Kaya Date: Wed, 29 Jan 2025 16:50:02 +0000 Subject: [PATCH] fix: Don't crash when `score.total` is missing (#682) Fixes #681. --- .changeset/rude-tomatoes-brush.md | 8 ++++++++ .../overlay/src/integrations/sentry/utils/webVitals.ts | 6 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 .changeset/rude-tomatoes-brush.md diff --git a/.changeset/rude-tomatoes-brush.md b/.changeset/rude-tomatoes-brush.md new file mode 100644 index 00000000..d525ca1d --- /dev/null +++ b/.changeset/rude-tomatoes-brush.md @@ -0,0 +1,8 @@ +--- +'@spotlightjs/spotlight': patch +'@spotlightjs/electron': patch +'@spotlightjs/overlay': patch +'@spotlightjs/astro': patch +--- + +Fix rare error when `score.total` is missing from `measurements` diff --git a/packages/overlay/src/integrations/sentry/utils/webVitals.ts b/packages/overlay/src/integrations/sentry/utils/webVitals.ts index a73fd7d8..60ecdbce 100644 --- a/packages/overlay/src/integrations/sentry/utils/webVitals.ts +++ b/packages/overlay/src/integrations/sentry/utils/webVitals.ts @@ -1,5 +1,5 @@ -import { SentryEvent } from '~/integrations/sentry/types'; -import { WebVitals } from '../constants'; +import type { SentryEvent } from '~/integrations/sentry/types'; +import type { WebVitals } from '../constants'; const SQRT_2 = Math.sqrt(2); @@ -155,7 +155,7 @@ export function normalizePerformanceScore( }; } - if (shouldAddTotal) { + if (shouldAddTotal && !Object.prototype.hasOwnProperty.call(measurements, 'score.total')) { measurements['score.total'] = { value: scoreTotal, unit: 'ratio',