Skip to content

Commit

Permalink
Don't send tracing spans if performance.measure doesn't return measur…
Browse files Browse the repository at this point in the history
…ements

Fixes #54389.

Old versions of Safari appear to return `undefined` from `performance.measure()` instead of `PerformanceMeasure` values.
  • Loading branch information
wbinnssmith committed Aug 31, 2023
1 parent ac56bca commit 7ee7ddc
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions packages/next/src/client/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7ee7ddc

Please sign in to comment.