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 (#54808)

Fixes #54389.

Old versions of Safari appear to return `undefined` from `performance.measure()` instead of `PerformanceMeasure` values.


Closes WEB-1477
  • Loading branch information
wbinnssmith committed Aug 31, 2023
1 parent cc77579 commit 1fc4b22
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions packages/next/src/client/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -466,19 +466,26 @@ 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 (
process.env.NODE_ENV === 'development' &&
// Old versions of Safari don't return `PerformanceMeasure`s from `performance.measure()`
beforeHydrationMeasure !== undefined &&
hydrationMeasure !== undefined
) {
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 1fc4b22

Please sign in to comment.