Skip to content

Commit

Permalink
use relayer
Browse files Browse the repository at this point in the history
  • Loading branch information
housseindjirdeh committed Nov 21, 2019
1 parent d1a54bd commit a9fdd5f
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions packages/next/client/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global location */
/* global location, hydrationMetrics */
import React from 'react'
import ReactDOM from 'react-dom'
import HeadManager from './head-manager'
Expand Down Expand Up @@ -368,7 +368,7 @@ function clearMeasures() {
].forEach(measure => performance.clearMeasures(measure))
}

function measureFid () {
function measureFid() {
hydrationMetrics.onInputDelay((delay, event) => {
const hydrationMeasures = performance.getEntriesByName(
'Next.js-hydration',
Expand All @@ -379,22 +379,26 @@ function measureFid () {
const { startTime, duration } = hydrationMeasures[0]
const hydrateEnd = startTime + duration

// TODO: Instead of console.logs, expose values to user code through perf relayer (next.js/pull/8480)
console.log(
'First input after hydration',
`start: ${event.timeStamp}`,
`delay: ${delay}`
)
console.log(
'Delta between hydration end and first input',
`diff: ${event.timeStamp - hydrateEnd}`
)
if (onPerfEntry) {
onPerfEntry({
name: 'first-input-delay-after-hydration',
startTime: event.timeStamp,
value: delay,
})
onPerfEntry({
name: 'time-to-first-input-after-hydration',
startTime: hydrateEnd,
value: event.timeStamp - hydrateEnd,
})
}
} else {
console.log(
'First input before hydration',
`start: ${event.timeStamp}`,
`delay: ${delay}`
)
if (onPerfEntry) {
onPerfEntry({
name: 'first-input-delay-before-hydration',
startTime: event.timeStamp,
value: delay,
})
}
}
})

Expand Down

0 comments on commit a9fdd5f

Please sign in to comment.