From 7b4d1d02e5db46c03a76f35983c485a9274f85fc Mon Sep 17 00:00:00 2001 From: Barry Pollard Date: Fri, 26 May 2023 11:10:05 +0100 Subject: [PATCH 1/3] Fix attribution types --- src/types/base.ts | 4 ++++ src/types/cls.ts | 10 ++++++++-- src/types/fcp.ts | 10 ++++++++-- src/types/fid.ts | 10 ++++++++-- src/types/inp.ts | 10 ++++++++-- src/types/lcp.ts | 5 +++-- src/types/ttfb.ts | 5 +++-- 7 files changed, 42 insertions(+), 12 deletions(-) diff --git a/src/types/base.ts b/src/types/base.ts index 3cce6b7f..f1e4b401 100644 --- a/src/types/base.ts +++ b/src/types/base.ts @@ -116,6 +116,10 @@ export interface ReportCallback { (metric: Metric): void; } +export interface ReportCallbackWithAttribution { + (metric: MetricWithAttribution): void; +} + export interface ReportOpts { reportAllChanges?: boolean; durationThreshold?: number; diff --git a/src/types/cls.ts b/src/types/cls.ts index 58dbce35..ef99741e 100644 --- a/src/types/cls.ts +++ b/src/types/cls.ts @@ -14,7 +14,12 @@ * limitations under the License. */ -import {LoadState, Metric, ReportCallback} from './base.js'; +import { + LoadState, + Metric, + ReportCallback, + ReportCallbackWithAttribution, +} from './base.js'; /** * A CLS-specific version of the Metric object. @@ -83,6 +88,7 @@ export interface CLSReportCallback extends ReportCallback { /** * A CLS-specific version of the ReportCallback function with attribution. */ -export interface CLSReportCallbackWithAttribution extends CLSReportCallback { +export interface CLSReportCallbackWithAttribution + extends ReportCallbackWithAttribution { (metric: CLSMetricWithAttribution): void; } diff --git a/src/types/fcp.ts b/src/types/fcp.ts index b7755629..ca65f4dd 100644 --- a/src/types/fcp.ts +++ b/src/types/fcp.ts @@ -14,7 +14,12 @@ * limitations under the License. */ -import {LoadState, Metric, ReportCallback} from './base.js'; +import { + LoadState, + Metric, + ReportCallback, + ReportCallbackWithAttribution, +} from './base.js'; import {NavigationTimingPolyfillEntry} from './polyfills.js'; /** @@ -75,6 +80,7 @@ export interface FCPReportCallback extends ReportCallback { /** * An FCP-specific version of the ReportCallback function with attribution. */ -export interface FCPReportCallbackWithAttribution extends FCPReportCallback { +export interface FCPReportCallbackWithAttribution + extends ReportCallbackWithAttribution { (metric: FCPMetricWithAttribution): void; } diff --git a/src/types/fid.ts b/src/types/fid.ts index a5449753..49ddd401 100644 --- a/src/types/fid.ts +++ b/src/types/fid.ts @@ -14,7 +14,12 @@ * limitations under the License. */ -import {LoadState, Metric, ReportCallback} from './base.js'; +import { + LoadState, + Metric, + ReportCallback, + ReportCallbackWithAttribution, +} from './base.js'; import {FirstInputPolyfillEntry} from './polyfills.js'; /** @@ -76,6 +81,7 @@ export interface FIDReportCallback extends ReportCallback { /** * An FID-specific version of the ReportCallback function with attribution. */ -export interface FIDReportCallbackWithAttribution extends FIDReportCallback { +export interface FIDReportCallbackWithAttribution + extends ReportCallbackWithAttribution { (metric: FIDMetricWithAttribution): void; } diff --git a/src/types/inp.ts b/src/types/inp.ts index cc1a0794..ec9c5e76 100644 --- a/src/types/inp.ts +++ b/src/types/inp.ts @@ -14,7 +14,12 @@ * limitations under the License. */ -import {LoadState, Metric, ReportCallback} from './base.js'; +import { + LoadState, + Metric, + ReportCallback, + ReportCallbackWithAttribution, +} from './base.js'; /** * An INP-specific version of the Metric object. @@ -75,6 +80,7 @@ export interface INPReportCallback extends ReportCallback { /** * An INP-specific version of the ReportCallback function with attribution. */ -export interface INPReportCallbackWithAttribution extends INPReportCallback { +export interface INPReportCallbackWithAttribution + extends ReportCallbackWithAttribution { (metric: INPMetricWithAttribution): void; } diff --git a/src/types/lcp.ts b/src/types/lcp.ts index b2418dbe..4aedd4ff 100644 --- a/src/types/lcp.ts +++ b/src/types/lcp.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import {Metric, ReportCallback} from './base.js'; +import {Metric, ReportCallback, ReportCallbackWithAttribution} from './base.js'; import {NavigationTimingPolyfillEntry} from './polyfills.js'; /** @@ -98,6 +98,7 @@ export interface LCPReportCallback extends ReportCallback { /** * An LCP-specific version of the ReportCallback function with attribution. */ -export interface LCPReportCallbackWithAttribution extends LCPReportCallback { +export interface LCPReportCallbackWithAttribution + extends ReportCallbackWithAttribution { (metric: LCPMetricWithAttribution): void; } diff --git a/src/types/ttfb.ts b/src/types/ttfb.ts index 5b7b62b5..66fa23ac 100644 --- a/src/types/ttfb.ts +++ b/src/types/ttfb.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import {Metric, ReportCallback} from './base.js'; +import {Metric, ReportCallback, ReportCallbackWithAttribution} from './base.js'; import {NavigationTimingPolyfillEntry} from './polyfills.js'; /** @@ -76,6 +76,7 @@ export interface TTFBReportCallback extends ReportCallback { /** * A TTFB-specific version of the ReportCallback function with attribution. */ -export interface TTFBReportCallbackWithAttribution extends TTFBReportCallback { +export interface TTFBReportCallbackWithAttribution + extends ReportCallbackWithAttribution { (metric: TTFBMetricWithAttribution): void; } From 3b955723f40f7cd36f64ee5089d4583ba622574d Mon Sep 17 00:00:00 2001 From: Barry Pollard Date: Fri, 26 May 2023 11:22:42 +0100 Subject: [PATCH 2/3] Fix CLS --- package-lock.json | 4 ++-- package.json | 2 +- src/attribution/onCLS.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index c52908a2..eeacdcf2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "web-vitals", - "version": "3.3.1", + "version": "3.3.1-types", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "web-vitals", - "version": "3.3.1", + "version": "3.3.1-types", "license": "Apache-2.0", "devDependencies": { "@babel/core": "^7.21.0", diff --git a/package.json b/package.json index fb708f67..511eec5e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "web-vitals", - "version": "3.3.1", + "version": "3.3.1-types", "description": "Easily measure performance metrics in JavaScript", "type": "module", "typings": "dist/modules/index.d.ts", diff --git a/src/attribution/onCLS.ts b/src/attribution/onCLS.ts index 0e62a7d8..1b86b85d 100644 --- a/src/attribution/onCLS.ts +++ b/src/attribution/onCLS.ts @@ -81,7 +81,7 @@ export const onCLS = ( opts?: ReportOpts ) => { unattributedOnCLS( - ((metric: CLSMetric) => { + ((metric: CLSMetricWithAttribution) => { attributeCLS(metric); onReport(metric); }) as CLSReportCallback, From ed9cdd101aa9266e5feadcb9fe3c3c7a921fd0f9 Mon Sep 17 00:00:00 2001 From: Barry Pollard Date: Fri, 26 May 2023 11:28:35 +0100 Subject: [PATCH 3/3] Revert version update --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index eeacdcf2..c52908a2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "web-vitals", - "version": "3.3.1-types", + "version": "3.3.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "web-vitals", - "version": "3.3.1-types", + "version": "3.3.1", "license": "Apache-2.0", "devDependencies": { "@babel/core": "^7.21.0", diff --git a/package.json b/package.json index 511eec5e..fb708f67 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "web-vitals", - "version": "3.3.1-types", + "version": "3.3.1", "description": "Easily measure performance metrics in JavaScript", "type": "module", "typings": "dist/modules/index.d.ts",