Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
add global callback for refresh latency (vercel#25944)
Browse files Browse the repository at this point in the history
Co-authored-by: JJ Kasper <jj@jjsweb.site>
  • Loading branch information
sokra and ijjk committed Jun 9, 2021
1 parent a881735 commit ac11129
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/next/client/dev/error-overlay/hot-dev-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,11 @@ function onFastRefresh(hasUpdates) {
DevOverlay.onRefresh()
}

console.log('[Fast Refresh] done')
const latency = Date.now() - startLatency
console.log(`[Fast Refresh] done in ${latency}ms`)
if (self.__NEXT_HMR_LATENCY_CB) {
self.__NEXT_HMR_LATENCY_CB(latency)
}
}

// There is a newer version of the code available.
Expand All @@ -188,11 +192,14 @@ function handleAvailableHash(hash) {
mostRecentCompilationHash = hash
}

let startLatency = undefined

// Handle messages from the server.
function processMessage(e) {
const obj = JSON.parse(e.data)
switch (obj.action) {
case 'building': {
startLatency = Date.now()
console.log('[Fast Refresh] rebuilding')
break
}
Expand Down

0 comments on commit ac11129

Please sign in to comment.