Skip to content

Commit

Permalink
Ensure Web Vitals reporting is called
Browse files Browse the repository at this point in the history
  • Loading branch information
Timer committed Oct 16, 2020
1 parent 245499a commit 0466701
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/next/client/index.tsx
Expand Up @@ -462,10 +462,6 @@ function renderReactElement(reactEl: JSX.Element, domEl: HTMLElement) {
if (isInitialRender) {
ReactDOM.hydrate(reactEl, domEl, markHydrateComplete)
isInitialRender = false

if (onPerfEntry && ST) {
measureWebVitals(onPerfEntry)
}
} else {
ReactDOM.render(reactEl, domEl, markRenderComplete)
}
Expand Down Expand Up @@ -744,5 +740,12 @@ function Root({
}
}, [])
}
// We should ask to measure the Web Vitals after rendering completes so we
// don't cause any hydration delay:
React.useEffect(() => {
if (onPerfEntry) {
measureWebVitals(onPerfEntry)
}
}, [])
return children as React.ReactElement
}

0 comments on commit 0466701

Please sign in to comment.