From 7afafb28edf2c52d1a7e14908ae77c23cc6140ee Mon Sep 17 00:00:00 2001 From: fliiiix Date: Fri, 11 Oct 2024 08:42:29 +0200 Subject: [PATCH] fix(web): New reportWebVitals No clue why we need this in the first place https://stackoverflow.com/a/78898219 --- web/src/reportWebVitals.ts | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/web/src/reportWebVitals.ts b/web/src/reportWebVitals.ts index 491822c83..9b882a3b0 100644 --- a/web/src/reportWebVitals.ts +++ b/web/src/reportWebVitals.ts @@ -1,19 +1,15 @@ -import { type ReportHandler } from 'web-vitals' +import { ReportCallback } from "web-vitals"; -const reportWebVitals = (onPerfEntry?: ReportHandler): void => { - if (onPerfEntry == null || !(onPerfEntry instanceof Function)) { - return +const reportWebVitals = (onPerfEntry?: ReportCallback) => { + if (onPerfEntry && onPerfEntry instanceof Function) { + import("web-vitals").then(({ onCLS, onINP, onFCP, onLCP, onTTFB }) => { + onCLS(onPerfEntry); + onINP(onPerfEntry); + onFCP(onPerfEntry); + onLCP(onPerfEntry); + onTTFB(onPerfEntry); + }); } +}; - void import('web-vitals').then( - ({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { - getCLS(onPerfEntry) - getFID(onPerfEntry) - getFCP(onPerfEntry) - getLCP(onPerfEntry) - getTTFB(onPerfEntry) - } - ) -} - -export default reportWebVitals +export default reportWebVitals;