Skip to content

Commit

Permalink
Replace removed Web Vitals methods
Browse files Browse the repository at this point in the history
Web Vitals v3 deprecated several methods and types, and v4 fully removed
them. This commit adapts our code to the breaking changes.

Note that the breaking removal of the `ReportHandler` type has been
complained about[1] and may return in deprecated form[2], but we should
go ahead and replace it anyway with the suggested inline typedef.

[1] GoogleChrome/web-vitals#482
[2] GoogleChrome/web-vitals#483

PR #745 Bump web-vitals from 3.5.2 to 4.0.0
  • Loading branch information
reefdog committed May 20, 2024
1 parent 66d162b commit 4d07fe9
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/reportWebVitals.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { getCLS, getFID, getFCP, getLCP, getTTFB } from 'web-vitals';
import type { Metric, ReportHandler } from 'web-vitals';
import { onCLS, onFID, onFCP, onLCP, onTTFB } from 'web-vitals';
import type { Metric } from 'web-vitals';

import { getLogger } from './logger';

const reportWebVitals = () => {
const logger = getLogger('web-vitals');
const reportHandler: ReportHandler = (metric: Metric) => logger.info(metric);
getCLS(reportHandler);
getFID(reportHandler);
getFCP(reportHandler);
getLCP(reportHandler);
getTTFB(reportHandler);
const reportHandler: (metric: Metric) => void = (metric: Metric) =>
logger.info(metric);
onCLS(reportHandler);
onFID(reportHandler);
onFCP(reportHandler);
onLCP(reportHandler);
onTTFB(reportHandler);
};

export { reportWebVitals };

0 comments on commit 4d07fe9

Please sign in to comment.