You should not always rely on remote debugging (React Native)

Suyog Krazz
2 min readOct 31, 2017

--

Remote Debugging in React Native is quite fun experience till you find out that when using the chrome debugger, react native uses a different JS engine. The chrome JS engine is used during debugging, but JavaScriptCore is used otherwise. Due to this subtle differences between the JavaScript execution environments on the device, and in your remote debugger , you can run on quite unique problems in your project.

JavaScript Runtime When using React Native, you’re going to be running your JavaScript code in two environments:

On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn’t use JIT due to the absence of writable executable memory in iOS apps.

When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.

Have you ever run into issue whereDate constructor seems to accept the locale-specific date formats in the debugging mode but not on the real device.

Congratulation!! You’ve run into one of the many edge cases that make remote debugging in React Native unreliable. For Example ,When you change a date to locale date string , it will give different version depending upon remote debugging on/off which may cause issue in your codebase.

When debugging is off

new Date("2017-02-12 23:51:31").toLocaleDateString('en-US', { day: '2-digit', month: 'short' })  // 02/12/17

When debugging is on

new Date("2017-02-12 23:51:31").toLocaleDateString('en-US', { day: '2-digit', month: 'short' })  // Feb 12

So , it’s better to use alternatives like momentJS instead of relying blindly on the JS of the environment doing which can lead to inconsistencies.

moment(new Date("2017-02-12 23:51:31")).format('ll') // Feb 12, 2017

This is why you should always test all features on a real device without the debugger before production. Cheers!!

--

--