Skip to content

Commit

Permalink
Upgrade web vitals to v4 (#318)
Browse files Browse the repository at this point in the history
* fix: 🗑️ update deprecated web vitals

Replace "ReportHandler" with (metric: MetricType) => void. Replace "getXXX" functions with "onXXX".

* chore: ⬆️ upgrade web vitals to v4
  • Loading branch information
phibkro authored Oct 15, 2024
1 parent c42d50f commit 4eeb2b5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"typescript": "^5.4.5",
"vaul": "^1.0.0",
"vite": "^5.2.10",
"web-vitals": "^3.0.0"
"web-vitals": "^4.2.3"
},
"devDependencies": {
"@biomejs/biome": "1.8.3",
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions src/reportWebVitals.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { ReportHandler } from "web-vitals";
import type { MetricType } from "web-vitals";

const reportWebVitals = (onPerfEntry?: ReportHandler): void => {
const reportWebVitals = (onPerfEntry?: (metric: MetricType) => void): void => {
if (onPerfEntry && onPerfEntry instanceof Function) {
import("web-vitals").then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
getCLS(onPerfEntry);
getFID(onPerfEntry);
getFCP(onPerfEntry);
getLCP(onPerfEntry);
getTTFB(onPerfEntry);
import("web-vitals").then(({ onCLS, onINP, onFCP, onLCP, onTTFB }) => {
onCLS(onPerfEntry);
onINP(onPerfEntry);
onFCP(onPerfEntry);
onLCP(onPerfEntry);
onTTFB(onPerfEntry);
});
}
};
Expand Down

0 comments on commit 4eeb2b5

Please sign in to comment.