infinitered / reactotron

A desktop app for inspecting your React JS and React Native projects. macOS, Linux, and Windows.
https://docs.infinite.red/reactotron/
MIT License
14.69k stars 935 forks source link

Reactotron will crash first app runs on real iOS devices #1473

Closed lindboe closed 1 month ago

lindboe commented 2 months ago

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

karam1ashqar commented 2 months ago

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

migueldaipre commented 2 months ago

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

lindboe commented 2 months ago

@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.

migueldaipre commented 2 months ago

@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

reeq-dev commented 2 months ago

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

karam1ashqar commented 2 months ago

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

ipakhomov commented 2 months ago

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.

lindboe commented 2 months ago

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.