Skip to content

Commit 00c00f2

Browse files
sokraijjk
andauthored
add global callback for refresh latency (#25944)
Co-authored-by: JJ Kasper <[email protected]>
1 parent a008d01 commit 00c00f2

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

packages/next/client/dev/error-overlay/hot-dev-client.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,11 @@ function onFastRefresh(hasUpdates) {
179179
DevOverlay.onRefresh()
180180
}
181181

182-
console.log('[Fast Refresh] done')
182+
const latency = Date.now() - startLatency
183+
console.log(`[Fast Refresh] done in ${latency}ms`)
184+
if (self.__NEXT_HMR_LATENCY_CB) {
185+
self.__NEXT_HMR_LATENCY_CB(latency)
186+
}
183187
}
184188

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

195+
let startLatency = undefined
196+
191197
// Handle messages from the server.
192198
function processMessage(e) {
193199
const obj = JSON.parse(e.data)
194200
switch (obj.action) {
195201
case 'building': {
202+
startLatency = Date.now()
196203
console.log('[Fast Refresh] rebuilding')
197204
break
198205
}

0 commit comments

Comments
 (0)