I have an issue with unstable_Profiler
on my React-Native project that is ignoring onRender callback, but only in production mode. No errors, everything renders fine. I went by this article: https://itnext.io/react-native-profiler-43d131130c5c
I tested solution on dev mode (react-native run-android) and everything worked perfect. Production build of app is not working.I tried recent versions of react and react-native, react-dom, schedule, scheduler, modify .babelrc but nothing worked for me.
import React, { unstable_Profiler as Profiler } from 'react';const withProfiler = (profilerId) => (WrappedComponent) => { class ProfilerComponent extends React.Component { async logMeasurement(id, phase, actualDuration, baseDuration) { // see output during DEV console.log({id, phase, actualDuration, baseDuration}); // also here is some logic to log durations in prod mode. (eg. logcat) // but it never happened. } render() { return (<Profiler id={profilerId} onRender={this.logMeasurement}><WrappedComponent {...this.props} /></Profiler> ); } } return ProfilerComponent;};export default withProfiler;
.babelrc
{"presets": ["module:metro-react-native-babel-preset" ],"plugins": [ ["module-resolver", {"root": ["./"],"alias": {"react-dom$": "react-dom/profiling","scheduler/tracing": "scheduler/tracing-profiling" } }] ],"env": {"production": {"plugins": ["transform-remove-console", ] },"development": {"plugins": ["@babel/plugin-transform-react-jsx-source" ] } }}
package.json
"react": "^16.8.1","react-native": "^0.57.8","react-dom": "16.8.1","react-art": "16.8.1","schedule": "^0.4.0","scheduler": "^0.13.1","@babel/core": "7.1.0","@babel/plugin-proposal-decorators": "^7.3.0","@babel/plugin-transform-react-jsx-source": "^7.2.0","@babel/preset-env": "^7.3.1","@babel/register": "^7.0.0","babel-core": "^7.0.0-bridge.0","babel-loader": "^8.0.4","babel-plugin-module-resolver": "^3.1.3","babel-plugin-transform-remove-console": "^6.9.4","metro-react-native-babel-preset": "^0.48.1",
Expected result is that logMeasurement
method is running in production app.
EDIT
I have invalid binding of logMeasurement
. Here is how I fixed it.
logMeasurement = async (id, phase, actualDuration, baseDuration) => { ... }
However, it did't fix the issue. The callback is still not called.