From 7ceaea1fc1ba33a34c546dc386a5c1e2358542bc Mon Sep 17 00:00:00 2001 From: Awais Ansari <79941147+awais-ansari@users.noreply.github.com> Date: Mon, 8 May 2023 12:28:38 +0500 Subject: [PATCH] chore: enable profiler on production build (#510) --- src/index.jsx | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/index.jsx b/src/index.jsx index aee6c6a1..9251f656 100755 --- a/src/index.jsx +++ b/src/index.jsx @@ -1,3 +1,4 @@ +/* eslint-disable no-underscore-dangle */ import 'core-js/stable'; import 'regenerator-runtime/runtime'; @@ -39,14 +40,31 @@ function onRenderCallback( console.log(`Interactions: ${interactions}`); } +function enableProfiler() { + console.log('Enabling React Profiler'); + if ( + process.env.NODE_ENV === 'production' + && typeof window !== 'undefined' + && window.__REACT_DEVTOOLS_GLOBAL_HOOK__ + && typeof window.__REACT_DEVTOOLS_GLOBAL_HOOK__.inject === 'function' + ) { + window.__REACT_DEVTOOLS_GLOBAL_HOOK__.inject({ + onRender: onRenderCallback, + }); + } +} + subscribe(APP_READY, () => { ReactDOM.render( - + , document.getElementById('root'), + () => { + enableProfiler(); + }, ); });