oblador / react-native-performance

📐 Monitor and measure React Native performance

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Profiling in production

henninghall opened this issue · comments

React Profiler seem to be missing in production bundles by default and render tracing is therefore not working in production builds.

Here is an explanation on how to enable react profiling with webpack or create react app. Is there a way to enable this in react native / metro?


To reproduce:

  1. Clone this repo and run vanilla project.
  2. Put an alert within the traceRender() in App.tsx.
  3. Run android
  4. Open dev menu -> Settings -> Disable "JS Dev Mode" -> Reload app
  5. Alerts are only shown in DEV mode.

Found a solution with this patch.

diff --git a/node_modules/react-native/Libraries/Renderer/shims/ReactNative.js b/node_modules/react-native/Libraries/Renderer/shims/ReactNative.js
index debaf0a..81744db 100644
--- a/node_modules/react-native/Libraries/Renderer/shims/ReactNative.js
+++ b/node_modules/react-native/Libraries/Renderer/shims/ReactNative.js
@@ -19,7 +19,7 @@ let ReactNative;
 if (__DEV__) {
   ReactNative = require('../implementations/ReactNativeRenderer-dev');
 } else {
-  ReactNative = require('../implementations/ReactNativeRenderer-prod');
+  ReactNative = require('../implementations/ReactNativeRenderer-profiling');
 }

 module.exports = (ReactNative: ReactNativeType);