reactotron icon indicating copy to clipboard operation
reactotron copied to clipboard

Reactotron will crash first app runs on real iOS devices

Open lindboe opened this issue 10 months ago • 8 comments

Describe the bug

On the first run of an RN app on a real iOS device (dev build), Reactotron will throw invalid host, which can lead to crashing the app (here because we were trying to add the reactotron redux enhancer to the store, but that failed, so the store failed to be created, crashing the app).

I think the underlying cause of this particular crash is because we need to click "Allow" to find devices on the local network. After pressing "Allow" and reloading, the app works fine.

In addition, Reactotron should be more resilient to errors like this and avoid crashing apps. It should:

  1. Ensure that any auto-generated hostname or other config never fails the validate test for hostname
  2. Ensure validate tests don't crash the app if they fail. Utilities that depend on Reactotron plugins would ideally return a no-op version (e.g., the redux enhancer) so that the app can continue to work.
  3. Errors from validate should make it more clear that they're from Reactotron in the message

Notes:

  1. This may depend on which version of RN you're on. I saw it on RN 71, but I do see the underlying code to get the source code URL in RN has been changed since. This could mean differences in whether "permission" is needed?
  2. I don't know of a simple way to "wait" until "Allow" has been pressed, so the fix would be to ensure we don't crash the app and then also notify users they'll need to reload the app for it to connect to Reactotron (with docs or a yellow box warning)

reactotron-react-native: 5.1.6

Reactotron version

3.7.0

lindboe avatar Apr 26 '24 18:04 lindboe

@morganick this happens since 5.0.4 version, you can use 5.0.3

karam1ashqar avatar Apr 28 '24 20:04 karam1ashqar

Same here for RN 0.73.7, invalid host in debug mode and crash in release mode (test flight).

migueldaipre avatar Apr 30 '24 14:04 migueldaipre

@migueldaipre Are you conditionally requiring Reactotron so that it only exists in dev everywhere you use it in your app? Reactotron shouldn't exist in your release mode app at all. e.g., https://github.com/infinitered/reactotron/blob/e41f12887ff8da7f5ede6fcf5884989a52e8b7e5/docs/quick-start/react-native.md?plain=1#L95-L97.

lindboe avatar Apr 30 '24 15:04 lindboe

@migueldaipre Are you conditionally requiring Reactotron so that it only exists in dev everywhere you use it in your app? Reactotron shouldn't exist in your release mode app at all. e.g.,

https://github.com/infinitered/reactotron/blob/e41f12887ff8da7f5ede6fcf5884989a52e8b7e5/docs/quick-start/react-native.md?plain=1#L95-L97

.

Hmm, I think I've found the problem, I call Reactotron.configure conditionally ...

But the reactotron import is still in the file.

That's probably it. Thanks @lindboe

migueldaipre avatar Apr 30 '24 16:04 migueldaipre

Same on 0.74.0. App has a hard crash on launch only in release versions. reactotron-react-native: 5.1.6

reeq-dev avatar May 01 '24 08:05 reeq-dev

use "reactotron-react-native": "5.0.3", and you won't have the crash in TestFlight or Release @reeq-dev , also make sure to have the correct setup as README.md

karam1ashqar avatar May 01 '24 08:05 karam1ashqar

Here is the workaround without downgrading Reactotron. As pointed above, make sure you don't have reactotron's code imported in release builds. Can be achieved by conditional require in DEV mode:

// reactotron-setup.ts
export const setupReactotron = () => {
  if (__DEV__) {
    const AsyncStorage = require('@react-native-async-storage/async-storage').default;
    const Reactotron: ReactotronReactNative = require('reactotron-react-native').default;
    const { reactotronRedux } = require('reactotron-redux');

    return Reactotron.configure({ name: 'React Native Demo' })
      .setAsyncStorageHandler(AsyncStorage)
      .use(reactotronRedux())
      .useReactNative({ log: true })
      .connect();
  }

  return undefined;
};

Then call the setup function wherever you need.

ipakhomov avatar May 01 '24 09:05 ipakhomov

Please keep discussion to the issue described in this ticket: Reactron crashing in dev with invalid host. If you have a different issue, please open a new ticket.

lindboe avatar May 01 '24 16:05 lindboe