Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
lindboe opened this issue Apr 26, 2024 · 8 comments · Fixed by #1476
Closed

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

lindboe opened this issue Apr 26, 2024 · 8 comments · Fixed by #1476
Assignees
Labels
bug 🪲 Nope, this is wrong.

Comments

@lindboe
Copy link
Contributor

lindboe commented Apr 26, 2024

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

@morganick morganick self-assigned this Apr 26, 2024
@morganick morganick added the bug 🪲 Nope, this is wrong. label Apr 26, 2024
@karam1ashqar
Copy link

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

@migueldaipre
Copy link

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

@lindboe
Copy link
Contributor Author

lindboe commented Apr 30, 2024

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

if (__DEV__) {
require("./ReactotronConfig");
}
.

@migueldaipre
Copy link

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

if (__DEV__) {
require("./ReactotronConfig");
}

.

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
Copy link

reeq-dev commented May 1, 2024

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

@karam1ashqar
Copy link

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
Copy link

ipakhomov commented May 1, 2024

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
Copy link
Contributor Author

lindboe commented May 1, 2024

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.

morganick added a commit that referenced this issue May 15, 2024
## Please verify the following:

- [x] `yarn build-and-test:local` passes
- [x] I have added tests for any new features, if relevant
- [ ] `README.md` (or relevant documentation) has been updated with your
changes

## Describe your PR

Fixes #1473 where calling split on an invalid string throws a
`TypeError`.

In the event that the following line does not provide us with a valid
URL:

https://github.com/facebook/react-native/blob/b38f80aeb6ad986c64fd03f53b2e01a7990e1533/packages/react-native/React/CoreModules/RCTSourceCode.mm#L38

We should catch this and warn the user that we are falling back to the
default host:
```
WARN  getHost: "Invalid URL: null" for scriptURL - Falling back to localhost
```

## How to Reproduce

I was unable to reproduce this issue locally with my devices as it would
not crash the application, but just throw the error. Due to the
circumstances of the original issue and that applications configuration,
this should allow that application to continue to boot.

## Additional Notes

It is still possible to configure Reactotron with an invalid host. This
will equally throw an error of `invalid url`. I'd like to create a new
PR that allows the application to continue to function, keeps Reactotron
is a disconnected state, and notifies the user.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🪲 Nope, this is wrong.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants