diff --git a/README.md b/README.md index 6a4046a..1f25677 100644 --- a/README.md +++ b/README.md @@ -37,11 +37,19 @@ const reportPerformance = () => { // Logging is not critical for most application, // so you can avoid loading this library in initial bundle by using dynamic import. import("@openameba/cwv-logger").then( - ({ reportCLS, reportFID, reportLCP, reportTTFB }) => { + ({ reportCLS, reportFID, reportLCP, reportTTFB, reportINP }) => { reportCLS(handleReport); reportFID(handleReport); reportLCP(handleReport); reportTTFB(handleReport); + /** + * reportINP has option in second argument. + * @see https://github.com/GoogleChrome/web-vitals/tree/next + */ + reportINP(handleReport, { + reportAllChanges: false, // or true + durationThreshold: 40, // or number + }); } ); }; @@ -53,12 +61,13 @@ const reportPerformance = () => { - [Largest Contentful Paint(LCP)](https://web.dev/lcp/) - [First Input Delay(FID)](https://web.dev/fid/) - [Time to First Byte(TTFB)](https://web.dev/ttfb/) +- [Interaction to Next Paint(INP)](https://web.dev/inp/) ## Report params ```ts type ReportParams = { - metricsName: "CLS" | "LCP" | "FID" | "TTFB"; + metricsName: "CLS" | "LCP" | "FID" | "TTFB" | "INP"; metricsValue: number; // Get value from https://developer.mozilla.org/en-US/docs/Web/API/NetworkInformation/effectiveType. networkType: string; diff --git a/package.json b/package.json index e80314d..c8cfd67 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@openameba/cwv-logger", - "version": "0.1.0", + "version": "0.1.1-beta.1", "main": "./index.js", "module": "./index.mjs", "types": "./index.d.ts", @@ -26,20 +26,20 @@ }, "license": "MIT", "dependencies": { - "web-vitals": "^2.1.4" + "web-vitals": "^3.0.0-beta.2" }, "devDependencies": { "@types/jest": "^27.0.0", - "bundlesize": "^0.18.0", - "jest": "^27.0.0", - "ts-jest": "^27.0.0", "@typescript-eslint/eslint-plugin": "^5.0.0", "@typescript-eslint/parser": "^5.0.0", + "bundlesize": "^0.18.0", "eslint": "^7.5.0", "eslint-config-prettier": "^7.0.0", "eslint-plugin-prettier": "^3.1.4", - "typescript": "^4.0.0", + "jest": "^27.0.0", "npm-run-all": "^4.1.5", - "prettier": "^2.0.5" + "prettier": "^2.0.5", + "ts-jest": "^27.0.0", + "typescript": "^4.0.0" } } diff --git a/src/types.ts b/src/types.ts index 0bb465e..063b60b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -3,6 +3,7 @@ export const SupportedMetrics = { CLS: "CLS", FID: "FID", TTFB: "TTFB", + INP: "INP", } as const; export type ReportParams = { diff --git a/src/webVitals.ts b/src/webVitals.ts index 7ba8887..68b9474 100644 --- a/src/webVitals.ts +++ b/src/webVitals.ts @@ -1,11 +1,13 @@ import { FirstInputPolyfillEntry, - getCLS, - getFID, - getLCP, - getTTFB, + onCLS, + onFID, + onLCP, + onTTFB, + onINP, ReportHandler as WebVitalsReportHandler, Metric as WebVitalsMetrics, + ReportOpts, } from "web-vitals"; import { getElementName, getNetworkType } from "./base"; import { ReportParams, SupportedMetrics } from "./types"; @@ -43,12 +45,18 @@ type TimeToFirstByte = { name: typeof SupportedMetrics.TTFB; }; +type InteractionToNextPaint = { + name: typeof SupportedMetrics.INP; + entries: FirstInputPolyfillEntry[]; +}; + type Metrics = BaseMetrics & ( | LargestContentfulPaint | FirstInputDelay | CumulativeLayoutShift | TimeToFirstByte + | InteractionToNextPaint ); /** @@ -97,7 +105,10 @@ function getLargestLayoutShiftSource( export type ReportCallback = (params: ReportParams) => void; -type Report = (report: ReportCallback) => void; +type Report