From 7ee7ddc38afc5131985dea6010267ada77f4a37e Mon Sep 17 00:00:00 2001 From: Will Binns-Smith Date: Wed, 30 Aug 2023 20:25:26 -0700 Subject: [PATCH] Don't send tracing spans if performance.measure doesn't return measurements Fixes #54389. Old versions of Safari appear to return `undefined` from `performance.measure()` instead of `PerformanceMeasure` values. --- packages/next/src/client/index.tsx | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/packages/next/src/client/index.tsx b/packages/next/src/client/index.tsx index cd0a8d601bfb2..3432464e29093 100644 --- a/packages/next/src/client/index.tsx +++ b/packages/next/src/client/index.tsx @@ -466,19 +466,22 @@ function markHydrateComplete(): void { 'afterHydrate' ) - tracer - .startSpan('navigation-to-hydration', { - startTime: performance.timeOrigin + beforeHydrationMeasure.startTime, - attributes: { - pathname: location.pathname, - query: location.search, - }, - }) - .end( - performance.timeOrigin + - hydrationMeasure.startTime + - hydrationMeasure.duration - ) + if (beforeHydrationMeasure !== undefined && hydrationMeasure !== undefined) { + // Old versions of Safari don't return `PerformanceMeasure`s from `performance.measure()` + tracer + .startSpan('navigation-to-hydration', { + startTime: performance.timeOrigin + beforeHydrationMeasure.startTime, + attributes: { + pathname: location.pathname, + query: location.search, + }, + }) + .end( + performance.timeOrigin + + hydrationMeasure.startTime + + hydrationMeasure.duration + ) + } if (onPerfEntry) { performance.getEntriesByName('Next.js-hydration').forEach(onPerfEntry)