From 3d611a8da523f2b28f0409a0099a8efe050bafab Mon Sep 17 00:00:00 2001 From: keiya01 Date: Fri, 3 Jun 2022 12:40:55 +0900 Subject: [PATCH 1/6] feat: use web-vitals@next --- package.json | 12 ++++++------ yarn.lock | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index e80314d..285c397 100644 --- a/package.json +++ b/package.json @@ -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/yarn.lock b/yarn.lock index fd26e66..23bcbd5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4036,10 +4036,10 @@ walker@^1.0.7: dependencies: makeerror "1.0.12" -web-vitals@^2.1.4: - version "2.1.4" - resolved "https://registry.yarnpkg.com/web-vitals/-/web-vitals-2.1.4.tgz#76563175a475a5e835264d373704f9dde718290c" - integrity sha512-sVWcwhU5mX6crfI5Vd2dC4qchyTqxV8URinzt25XqVh+bHEPGH4C3NPrNionCP7Obx59wrYEbNlw4Z8sjALzZg== +web-vitals@^3.0.0-beta.2: + version "3.0.0-beta.2" + resolved "https://registry.yarnpkg.com/web-vitals/-/web-vitals-3.0.0-beta.2.tgz#08c605295f36484256ee3acb5735b1f4dc9cd565" + integrity sha512-W9OALsWK4RkA5GWvLhsfszy+Q29WJBB27Dnucc3eYP6/0kz1XsfMgm+4au9X/KjXMIo92ZRU1fWBaSdNsaVjJg== webidl-conversions@^5.0.0: version "5.0.0" From 321eb4c763f07b6371389574cc282931cc8a5376 Mon Sep 17 00:00:00 2001 From: keiya01 Date: Fri, 3 Jun 2022 12:41:19 +0900 Subject: [PATCH 2/6] feat: add reportINP method --- src/types.ts | 1 + src/webVitals.ts | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) 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..f1b5462 100644 --- a/src/webVitals.ts +++ b/src/webVitals.ts @@ -4,8 +4,10 @@ import { getFID, getLCP, getTTFB, + 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