Skip to content

Commit

Permalink
rename to useExperimentalWebVitalsReport
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Sep 24, 2021
1 parent 4a7404c commit fc65092
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/next/vitals/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { useWebVitalsReport } from './vitals'
export { useExperimentalWebVitalsReport } from './vitals'
4 changes: 3 additions & 1 deletion packages/next/vitals/vitals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ export function trackWebVitalMetric(metric: NextWebVitalsMetric) {
webVitalsCallbacks.forEach((callback) => callback(metric))
}

export function useWebVitalsReport(callback: ReportWebVitalsCallback) {
export function useExperimentalWebVitalsReport(
callback: ReportWebVitalsCallback
) {
const metricIndexRef = useRef(0)

useEffect(() => {
Expand Down
8 changes: 4 additions & 4 deletions test/integration/relay-analytics/pages/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* global localStorage */
import { useWebVitalsReport } from 'next/vitals'
import { useExperimentalWebVitalsReport } from 'next/vitals'

if (typeof navigator !== 'undefined') {
window.__BEACONS = window.__BEACONS || []
Expand All @@ -21,8 +21,8 @@ if (typeof navigator !== 'undefined') {

export default () => {
// Below comment will be used for replacing exported report method with hook based one.
///* useWebVitalsReport
useWebVitalsReport((data) => {
///* useExperimentalWebVitalsReport
useExperimentalWebVitalsReport((data) => {
const name = data.name || data.entryType
localStorage.setItem(
name,
Expand All @@ -31,7 +31,7 @@ export default () => {
const countMap = window.__BEACONS_COUNT
countMap.set(name, (countMap.get(name) || 0) + 1)
})
// useWebVitalsReport */
// useExperimentalWebVitalsReport */

return (
<div>
Expand Down
4 changes: 2 additions & 2 deletions test/integration/relay-analytics/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ async function killServer() {
describe('Analytics relayer with exported method', () => {
beforeAll(async () => {
// Keep app exported reporting and comment the hook one
indexPage.replace('///* useWebVitalsReport', '/*')
indexPage.replace('// useWebVitalsReport */', '*/')
indexPage.replace('///* useExperimentalWebVitalsReport', '/*')
indexPage.replace('// useExperimentalWebVitalsReport */', '*/')
await buildApp()
})
afterAll(async () => {
Expand Down

0 comments on commit fc65092

Please sign in to comment.