Skip to content

Commit

Permalink
Add ReportCallback type back but deprecate it (#483)
Browse files Browse the repository at this point in the history
* Add ReportCallback type back but deprecate it

* Update the Upgrading to v4 guide

* Update docs/upgrading-to-v4.md

Co-authored-by: Barry Pollard <barrypollard@google.com>

---------

Co-authored-by: Barry Pollard <barrypollard@google.com>
  • Loading branch information
philipwalton and tunetheweb authored May 22, 2024
1 parent 27f5d87 commit cae70b1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
13 changes: 11 additions & 2 deletions docs/upgrading-to-v4.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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._
9 changes: 9 additions & 0 deletions src/types/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit cae70b1

Please sign in to comment.