From 2bf608655c867f8cb6ae4d11953a1852fb9b2543 Mon Sep 17 00:00:00 2001 From: Awais Ansari <79941147+awais-ansari@users.noreply.github.com> Date: Fri, 5 May 2023 16:42:36 +0500 Subject: [PATCH] chore: enable profiler on production for data collection (#509) --- src/index.jsx | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/index.jsx b/src/index.jsx index 4ce7c614..aee6c6a1 100755 --- a/src/index.jsx +++ b/src/index.jsx @@ -1,7 +1,7 @@ import 'core-js/stable'; import 'regenerator-runtime/runtime'; -import React from 'react'; +import React, { Profiler } from 'react'; import ReactDOM from 'react-dom'; import { messages as footerMessages } from '@edx/frontend-component-footer'; @@ -20,11 +20,32 @@ import store from './store'; import './assets/favicon.ico'; import './index.scss'; +function onRenderCallback( + id, // the "id" prop of the Profiler tree that has just committed + phase, // either "mount" (if the tree just mounted) or "update" (if it re-rendered) + actualDuration, // time spent rendering the committed update + baseDuration, // estimated time to render the entire subtree without memoization + startTime, // when React began rendering this update + commitTime, // when React committed this update + interactions, // the Set of interactions belonging to this update +) { + // Aggregate or log render timings... + console.log(`Profiler ID: ${id}`); + console.log(`Phase: ${phase}`); + console.log(`Actual duration: ${actualDuration}`); + console.log(`Base duration: ${baseDuration}`); + console.log(`Start time: ${startTime}`); + console.log(`Commit time: ${commitTime}`); + console.log(`Interactions: ${interactions}`); +} + subscribe(APP_READY, () => { ReactDOM.render( - - - , + + + + + , document.getElementById('root'), ); });