File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed
Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -28,10 +28,18 @@ const theme = extendTheme({
2828 } ,
2929} ) ;
3030
31+ /**
32+ * Wraps the application UI with a ChakraProvider using the project theme and initializes web vitals on mount.
33+ *
34+ * Calls `initWebVitals` once when mounted to start web vitals collection.
35+ *
36+ * @param children - The React node(s) to render within the themed provider
37+ * @returns The React element tree where `children` are wrapped by a `ChakraProvider` configured with the module theme
38+ */
3139export function Providers ( { children } : { children : React . ReactNode } ) {
3240 useEffect ( ( ) => {
3341 initWebVitals ( ) ;
3442 } , [ ] ) ;
3543
3644 return < ChakraProvider theme = { theme } > { children } </ ChakraProvider > ;
37- }
45+ }
Original file line number Diff line number Diff line change @@ -53,6 +53,13 @@ function scheduleFlush() {
5353 } , FLUSH_INTERVAL_MS )
5454}
5555
56+ /**
57+ * Sends all queued web-vital and navigation-timing events to the server and clears the in-memory queue.
58+ *
59+ * If the queue is empty this is a no-op. Attempts to deliver using `navigator.sendBeacon` when available;
60+ * otherwise falls back to a POST request with `keepalive`. On network failure, logs a warning in non-production
61+ * environments and restores the events to the front of the queue so they are not lost.
62+ */
5663async function flushQueue ( ) {
5764 if ( queue . length === 0 ) {
5865 return
@@ -223,6 +230,12 @@ function installLifecycleFlush() {
223230 window . addEventListener ( 'beforeunload' , flush )
224231}
225232
233+ /**
234+ * Initializes collection and reporting of web-vitals and navigation timing data.
235+ *
236+ * This function is idempotent: calling it multiple times has no additional effect.
237+ * It is a no-op outside of a browser environment.
238+ */
226239export function initWebVitals ( ) {
227240 if ( typeof window === 'undefined' ) {
228241 return
You can’t perform that action at this time.
0 commit comments