Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename experimental vital hook #32343

Merged
merged 8 commits into from Dec 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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