Unverified Commit 15fcfb9c authored by Mimori's avatar Mimori Committed by GitHub

docs: fix navigationType value and variable name in useReportWebVitals (#90599)

## For Contributors

### Improving Documentation

- [x] Run `pnpm prettier-fix` to fix formatting issues before opening
the PR.
- [x] Read the Docs Contribution Guide to ensure your contribution
follows the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### What?

Fix two bugs in the `useReportWebVitals` API reference docs:

1. `navigationType` value `"back_forward"` → `"back-forward"`: the
`web-vitals`
library intentionally renames this value to use a hyphen for
consistency.
2. Variable name mismatch in `handleCustomMetrics` example: parameter
was named
`metrics` (plural) but the function body referenced `metric.name`
(singular),
   causing a `ReferenceError`.

### Why?

The `navigationType` description reflected the raw
`PerformanceNavigationTiming`
API value (`"back_forward"`), not the actual value emitted by the
`web-vitals`
library (`"back-forward"`), which `useReportWebVitals` is built on top
of
Ref: https://github.com/GoogleChrome/web-vitals?tab=readme-ov-file#types

The variable name mismatch in the code example would cause a
`ReferenceError`
if copied as-is.

### How?

- Updated `navigationType` description to use `"back-forward"`.
- Renamed parameter `metrics` → `metric` in the `handleCustomMetrics`
example

---------
Co-authored-by: 's avatarJoseph <sephxd1234@gmail.com>
Co-authored-by: 's avatarJoseph <joseph.chamochumbi@vercel.com>
parent ef993b25
...@@ -72,7 +72,7 @@ The `metric` object passed as the hook's argument consists of a number of proper ...@@ -72,7 +72,7 @@ The `metric` object passed as the hook's argument consists of a number of proper
- `name`: The name of the performance metric. Possible values include names of [Web Vitals](#web-vitals) metrics (TTFB, FCP, LCP, FID, CLS) specific to a web application. - `name`: The name of the performance metric. Possible values include names of [Web Vitals](#web-vitals) metrics (TTFB, FCP, LCP, FID, CLS) specific to a web application.
- `delta`: The difference between the current value and the previous value of the metric. The value is typically in milliseconds and represents the change in the metric's value over time. - `delta`: The difference between the current value and the previous value of the metric. The value is typically in milliseconds and represents the change in the metric's value over time.
- `entries`: An array of [Performance Entries](https://developer.mozilla.org/docs/Web/API/PerformanceEntry) associated with the metric. These entries provide detailed information about the performance events related to the metric. - `entries`: An array of [Performance Entries](https://developer.mozilla.org/docs/Web/API/PerformanceEntry) associated with the metric. These entries provide detailed information about the performance events related to the metric.
- `navigationType`: Indicates the [type of navigation](https://developer.mozilla.org/docs/Web/API/PerformanceNavigationTiming/type) that triggered the metric collection. Possible values include `"navigate"`, `"reload"`, `"back_forward"`, and `"prerender"`. - `navigationType`: Indicates the navigation type that triggered metric collection. Values are derived from [PerformanceNavigationTiming.type](https://developer.mozilla.org/docs/Web/API/PerformanceNavigationTiming/type) and may include `"navigate"`, `"reload"`, `"prerender"`, `"back-forward"` (normalized from `"back_forward"`), `"back-forward-cache"` (BFCache restore), and `"restore"` (page restored after discard).
- `rating`: A qualitative rating of the metric value, providing an assessment of the performance. Possible values are `"good"`, `"needs-improvement"`, and `"poor"`. The rating is typically determined by comparing the metric value against predefined thresholds that indicate acceptable or suboptimal performance. - `rating`: A qualitative rating of the metric value, providing an assessment of the performance. Possible values are `"good"`, `"needs-improvement"`, and `"poor"`. The rating is typically determined by comparing the metric value against predefined thresholds that indicate acceptable or suboptimal performance.
- `value`: The actual value or duration of the performance entry, typically in milliseconds. The value provides a quantitative measure of the performance aspect being tracked by the metric. The source of the value depends on the specific metric being measured and can come from various [Performance API](https://developer.mozilla.org/docs/Web/API/Performance_API)s. - `value`: The actual value or duration of the performance entry, typically in milliseconds. The value provides a quantitative measure of the performance aspect being tracked by the metric. The source of the value depends on the specific metric being measured and can come from various [Performance API](https://developer.mozilla.org/docs/Web/API/Performance_API)s.
...@@ -183,7 +183,7 @@ You can handle all the results of these metrics separately: ...@@ -183,7 +183,7 @@ You can handle all the results of these metrics separately:
```jsx filename="pages/_app.js" ```jsx filename="pages/_app.js"
import { useReportWebVitals } from 'next/web-vitals' import { useReportWebVitals } from 'next/web-vitals'
function handleCustomMetrics(metrics) { function handleCustomMetrics(metric) {
switch (metric.name) { switch (metric.name) {
case 'Next.js-hydration': case 'Next.js-hydration':
// handle hydration results // handle hydration results
...@@ -216,7 +216,7 @@ You can send results to any endpoint to measure and track ...@@ -216,7 +216,7 @@ You can send results to any endpoint to measure and track
real user performance on your site. For example: real user performance on your site. For example:
```js ```js
function postWebVitals(metrics) { function postWebVitals(metric) {
const body = JSON.stringify(metric) const body = JSON.stringify(metric)
const url = 'https://example.com/analytics' const url = 'https://example.com/analytics'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment