From cae70b105b8bba9c78c5ac40225f05a2b57f978a Mon Sep 17 00:00:00 2001 From: Philip Walton Date: Tue, 21 May 2024 20:15:34 -0700 Subject: [PATCH] Add ReportCallback type back but deprecate it (#483) * Add ReportCallback type back but deprecate it * Update the Upgrading to v4 guide * Update docs/upgrading-to-v4.md Co-authored-by: Barry Pollard --------- Co-authored-by: Barry Pollard --- docs/upgrading-to-v4.md | 13 +++++++++++-- src/types/base.ts | 9 +++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/docs/upgrading-to-v4.md b/docs/upgrading-to-v4.md index 19fc0de1..d3d2237d 100644 --- a/docs/upgrading-to-v4.md +++ b/docs/upgrading-to-v4.md @@ -1,8 +1,8 @@ # Upgrading to v4 -This document lists the full set of changes between version 3 and version 4 that are relevant to anyone wanting to upgrade to the new version. This document groups changes into "breaking changes" and "new features" across both the "standard" and "attribution" builds (see [build options](/#build-options) for details). +This document lists the full set of changes between version 3 and version 4 that are relevant to anyone wanting to upgrade to the new version. This document groups changes into "breaking changes", "new features", and "deprecations" across both the "standard" and "attribution" builds (see [build options](/#build-options) for details). -## ⚠️ Breaking changes +## ❌ Breaking changes ### Standard build @@ -56,3 +56,12 @@ No new features were introduced into the "standard" build, outside of the breaki #### `TTFBAttribution` - **Added** `cacheDuration`, which marks the total time spent checking the HTTP cache for a match ([#458](https://github.com/GoogleChrome/web-vitals/pull/458)). + +## ⚠️ Deprecations + +### Standard and attribution builds + +- The `onFID()` function [has been deprecated]https://web.dev/blog/inp-cwv-launch#fid_deprecation_timeline). Developers should use `onINP()` instead ([#435](https://github.com/GoogleChrome/web-vitals/pull/435)). +- The `ReportCallback` type has been deprecated in favor of explicit callback types for each metric function ([#483](https://github.com/GoogleChrome/web-vitals/pull/483)). + +_All deprecated APIs will be removed in the next major version._ diff --git a/src/types/base.ts b/src/types/base.ts index 9d574e90..f883affc 100644 --- a/src/types/base.ts +++ b/src/types/base.ts @@ -116,6 +116,15 @@ export type MetricWithAttribution = */ export type MetricRatingThresholds = [number, number]; +/** + * @deprecated Use metric-specific function types instead, such as: + * `(metric: LCPMetric) => void`. If a single callback type is needed for + * multiple metrics, use `(metric: MetricType) => void`. + */ +export interface ReportCallback { + (metric: MetricType): void; +} + export interface ReportOpts { reportAllChanges?: boolean; durationThreshold?: number;