Skip to content

onUrlChange crashes on load for Bare React Native projects that use Expo Modules  #105

@donatoaguirre24

Description

@donatoaguirre24

Describe the bug

We are using the MX Widget on bare React Native project that uses Expo Modules and recently had to update the SDK to the latest version to fix this issue.

The issue linked above got resolved, but now we're getting the following error:

[Mobile] ERROR  TypeError: Linking.addEventListener is not a function (it is undefined)
[Mobile]
[Mobile] This error is located at:
[Mobile]     in ConnectWidget (created by MXConnectScreen)
[Mobile]     in RCTView (created by View)
[Mobile]     in View

We haven't installed expo-linking in our project (is not in the yarn.lock either), but Linking = require("expo-linking") still resolves, but it doesn't export the Linking API. The catch block is never reached, causing the error above.

Steps to reproduce

[Steps to reproduce the behavior:]

  1. Create a bare react-native project and install expo-modules
  2. Install @mxenabled/react-native-widget-sdk
  3. Try to load the widget
  4. See error

Expected behavior

The widget loads successfully.

Screenshots

Sample code

      <ConnectWidget
        url={connectUrl}
        onEnterCredentials={(metadata) => {
          onConnectivityError?.();
        }}
        onMemberConnected={(metadata) => {
          onSuccess();
        }}
        onCreateMemberError={(metadata) => {
          onConnectivityError?.();
        }}
        onOAuthError={(metadata) => {
          onConnectivityError?.();
        }}
        onOAuthRequested={(metadata) => {
          Linking.openURL(metadata.url);
        }}
        onSubmitMFA={(metadata) => {
          onConnectivityError?.();
        }}
        style={{
          minWidth: WIDGET_MIN_WIDTH_PT,
          minHeight: '100%',
        }}
      />

Device information

  • Device: iPhone 16 Pro and Pixel 8
  • OS: iOS 18.2 and Android 14
  • React Native version: 0.74.6
  • MX React Native Widget SDK version: 1.1.4
  • Are you using Expo: Yes, through expo-modules, but I haven't installed expo-linking

Additional context

We were able to solve the issue by removing the following code using patch-package, and using the Linking provided by react-native rather than checking if Expo's it's available.

let Linking;
try {
    Linking = require("expo-linking");
}
catch (err) {
    Linking = RNLinking;
}

It would be great to check if the package it's installed in more reliable way, perhaps checking that the addEventListener method is available.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions