Skip to content

Hermes: Cannot set property 'preventInvalidHostname' of undefined #302

@aarondail

Description

@aarondail

In our RN 0.62.2 app, we are seeing crashes when we enable Hermes related to our use of URI.js https://medialize.github.io/URI.js/ ... in one case it seems like the UriJs object gets lost or something and becomes undefined, and we get exceptions like "Cannot set property 'preventInvalidHostname' of undefined" when we are trying to run code like UriJs.preventInvalidHostname = ...;

In more detail, we have a utility function called isUrlValid defined like this:

import UriJs from 'urijs';
// ...
export function isUrlValid(url: string): boolean {
  const preventInvalidHostname = UriJs.preventInvalidHostname;
  try {
    UriJs.preventInvalidHostname = true;
    UriJs.parse(url);
    return true;
  } catch (e) {
    return false;
  } finally {
    UriJs.preventInvalidHostname = preventInvalidHostname;
  }
}

This works totally fine w/ Hermes off, and with Hermes on it is usually fine. But, only in release builds and only in one case when isUrlValid is called, it will throw "Cannot set property 'preventInvalidHostname' of undefined".

It is totally weird.

I'd like to provide a repro... and I did try, but I failed. Practically speaking the only case where I can definitely say it happens is hard to separate from the rest of the code... and just calling the function by itself wont fail. So I am not sure how much of the rest of the code or even the state of the app is relevant to cause the bug to repro, and I can't invest a huge amount of time into it.

I know this without a repro there probably isn't too much that can be done, but I thought maybe you would have some thoughts or suggestions I could try. Or maybe this is related to another known issue (I did find some other issues that seemed somewhat similar, but not exactly the same as mine.)

  • I have run gradle clean and confirmed this bug does not occur with JSC"

Hermes version: 0.4.1
React Native version (if any): 0.62.2
Android version (if any): multiple, 7-10 at least
Platform: not 100% sure, but in Bugsnag crashes we see cpuAbi with values ["arm64-v8a", "armeabi-v7a", "armeabi"]

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingin-progressThe issue is being worked on

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions