Skip to content

Commit

Permalink
Rename vital hook
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Dec 9, 2021
1 parent 4d4f309 commit 0bd9ac7
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 20 deletions.
4 changes: 1 addition & 3 deletions packages/next/client/vitals.ts
Expand Up @@ -10,9 +10,7 @@ export function trackWebVitalMetric(metric: NextWebVitalsMetric) {
webVitalsCallbacks.forEach((callback) => callback(metric))
}

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

useEffect(() => {
Expand Down
8 changes: 0 additions & 8 deletions packages/next/taskfile.js
Expand Up @@ -1099,14 +1099,6 @@ export async function client(task, opts) {
notify('Compiled client files')
}

export async function vitals(task, opts) {
await task
.source(opts.src || 'vitals/**/*.+(js|ts|tsx)')
.swc('vitals', { dev: opts.dev })
.target('dist/vitals')
notify('Compiled vitals files')
}

// export is a reserved keyword for functions
export async function nextbuildstatic(task, opts) {
await task
Expand Down
2 changes: 1 addition & 1 deletion packages/next/vitals.d.ts
@@ -1 +1 @@
export { useExperimentalWebVitalsReport } from './dist/vitals/index'
export { unstable_useWebVitalsReport } from './dist/vitals/index'
4 changes: 2 additions & 2 deletions packages/next/vitals.js
@@ -1,4 +1,4 @@
module.exports = {
useExperimentalWebVitalsReport: require('./dist/client/vitals')
.useExperimentalWebVitalsReport,
unstable_useWebVitalsReport: require('./dist/client/vitals')
.unstable_useWebVitalsReport,
}
8 changes: 4 additions & 4 deletions test/integration/relay-analytics/pages/index.js
@@ -1,5 +1,5 @@
/* global localStorage */
import { useExperimentalWebVitalsReport } from 'next/vitals'
import { unstable_useWebVitalsReport } 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.
///* useExperimentalWebVitalsReport
useExperimentalWebVitalsReport((data) => {
///* unstable_useWebVitalsReport
unstable_useWebVitalsReport((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)
})
// useExperimentalWebVitalsReport */
// unstable_useWebVitalsReport */

return (
<div>
Expand Down
4 changes: 2 additions & 2 deletions test/integration/relay-analytics/test/index.test.js
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('///* useExperimentalWebVitalsReport', '/*')
indexPage.replace('// useExperimentalWebVitalsReport */', '*/')
indexPage.replace('///* unstable_useWebVitalsReport', '/*')
indexPage.replace('// unstable_useWebVitalsReport */', '*/')
await buildApp()
})
afterAll(async () => {
Expand Down

0 comments on commit 0bd9ac7

Please sign in to comment.