Skip to content

Commit

Permalink
Rename experimental vital hook (#32343)
Browse files Browse the repository at this point in the history
* Rename vital hook

* update taskfile

* disable hook rule for unstable prefix

* rename at exports

* fix typing

Co-authored-by: JJ Kasper <jj@jjsweb.site>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
3 people committed Dec 12, 2021
1 parent adbe237 commit 59a4432
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 22 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 useWebVitalsReport(callback: ReportWebVitalsCallback) {
const metricIndexRef = useRef(0)

useEffect(() => {
Expand Down
10 changes: 0 additions & 10 deletions packages/next/taskfile.js
Expand Up @@ -1036,7 +1036,6 @@ export async function compile(task, opts) {
'pages',
'lib',
'client',
'vitals',
'telemetry',
'trace',
'shared',
Expand Down Expand Up @@ -1099,14 +1098,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 Expand Up @@ -1181,7 +1172,6 @@ export default async function (task) {
await task.watch('build/**/*.+(js|ts|tsx)', 'nextbuild', opts)
await task.watch('export/**/*.+(js|ts|tsx)', 'nextbuildstatic', opts)
await task.watch('client/**/*.+(js|ts|tsx)', 'client', opts)
await task.watch('vitals/**/*.+(js|ts|tsx)', 'vitals', opts)
await task.watch('lib/**/*.+(js|ts|tsx)', 'lib', opts)
await task.watch('cli/**/*.+(js|ts|tsx)', 'cli', opts)
await task.watch('telemetry/**/*.+(js|ts|tsx)', 'telemetry', opts)
Expand Down
2 changes: 1 addition & 1 deletion packages/next/vitals.d.ts
@@ -1 +1 @@
export { useExperimentalWebVitalsReport } from './dist/vitals/index'
export { useWebVitalsReport as unstable_useWebVitalsReport } from './dist/client/vitals'
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')
.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 59a4432

Please sign in to comment.