Utilize CustomEvent Instead of Calling Exported reportWebVitals #52495
Replies: 2 comments
-
Hi @ragingwind, |
Beta Was this translation helpful? Give feedback.
-
This is a solid idea — more modern, hook-friendly, and powerful than the current reportWebVitals export. It would: Improve integration with React Make analytics + performance tracing easier Allow per-page or per-component context with vitals But: It needs guardrails to avoid event listener chaos It may need Next.js official support or a wrapper like useReportWebVitals() 💬 Final Thought If you're asking: “Is this a better architecture than export function reportWebVitals?” 👉 Honestly: yes. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Goals
Background
Currently, while hydrating on the local side, calling mod.reportWebVitals(webVitals), we are required to export reportWebVitals in _app.js. This approach has limitations when working with React components and hook, as reportWebVitals functions independently without any access to React component props. Consequently, there is a lack of information integration between props and webvital data. One thing I've concerned that is performance issues what I couldn't notice.
Proposal
Using custom event for web-vital which allow us get web-vital and next.js custom matrix at any component and hooks
AS-IS
TO-BE
Now, we can make a new hook for reportWebVitals
And, we can use it any component not only app
Beta Was this translation helpful? Give feedback.
All reactions