Skip to content

Commit

Permalink
guarantee called once
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Sep 23, 2021
1 parent dc7df16 commit ce661fb
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/next/vitals/vitals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ export function useWebVitalsReport(callback: ReportWebVitalsCallback) {

useEffect(() => {
// Flush calculated metrics
const reportMetric = (metric: NextWebVitalsMetric) => callback(metric)
const reportMetric = (metric: NextWebVitalsMetric) => {
callback(metric)
metricIndexRef.current = metrics.length
}
for (let i = metricIndexRef.current; i < metrics.length; i++) {
reportMetric(metrics[i])
}
metricIndexRef.current = metrics.length

webVitalsCallbacks.add(reportMetric)
return () => {
Expand Down

0 comments on commit ce661fb

Please sign in to comment.