launchdarkly / js-core

LaunchDarkly monorepo for JavaScript SDKs
Other
12 stars 12 forks source link

Does react-native-client-sdk (v10) support expo web? #455

Open QuanGao-osmind opened 1 month ago

QuanGao-osmind commented 1 month ago

Describe the bug We have an expo project that we are targeting both mobile and web platforms. The react-native-client-sdk works well on mobile but crashes in web.

This is the error I see:

autoEnv.js:24 Uncaught TypeError: Cannot read properties of undefined (reading 'Manufacturer')

which traces to this code in autoEnv, looks like Platform.constants is undefined.

export const ldDevice = {
    // key is populated by common/client-sdk
    key: '',
    envAttributesVersion: '1.0',
    manufacturer: Platform.select({
        ios: 'apple',
        android: Platform.constants.Manufacturer,
    }),
    model: Platform.select({
        // ios: model n/a from PlatformIOSStatic
        android: Platform.constants.Model,
    }),
    os: {
        family: Platform.select({
            ios: 'apple',
            default: Platform.OS,
        }),
        name: Platform.OS,
        version: (_a = Platform.Version) === null || _a === void 0 ? void 0 : _a.toString(),
    },
};

To reproduce Follow the SDK doc to initialize LD client and identify user.

Expected behavior Expect react-native-client-sdk to work on all platforms expo support (Android, IOS, web)

SDK version 10.1.3

OS/platform Web browser: Chrome Version 124.0.6367.62

Any insights are greatly appreciated, thank you!

louis-launchdarkly commented 1 month ago

@QuanGao-osmind Thank you so much - for other people who see this: LaunchDarkly team filed internally as 242760 for the investigation of disabling the web autoEnv, and @QuanGao-osmind also found out that once disabling this, there is also browser CORS security that we need to be concern about when we put a fix for this.

QuanGao-osmind commented 1 month ago

@louis-launchdarkly Thank you for the reply!

We are able to apply a patch to the package to get around the issue in autoEnv.

Do you have any suggestions in getting around the CORS issue?

yusinto commented 1 month ago

@QuanGao-osmind the react-native SDK is designed, built and tested for iOS and Android only. Other platforms are not supported. Web is not supported. The cors issue is due to http requests made to the LaunchDarkly mobile endpoints from a browser. We use different endpoints for these platforms and these are also coupled tightly with the use of mobile keys and client side ids.

louis-launchdarkly commented 1 month ago

Based on the investigation so far, while we have the feature request captured in the internal ticket I mentioned above, currently there is no ETA of when our RN SDK can support expo web. Trying to use the Client ID and the endpoints for the browser could be a thing to try.

QuanGao-osmind commented 1 month ago

@louis-launchdarkly @yusinto Thank you for the updates!

I thought react-native SDK is fully compatible with Expo because of the documentation here

Screenshot 2024-05-10 at 8 45 59 AM

If there's no immediate plan to support Expo web, could LD team update this documentation to reflect that?

FWIW we tested LD in Expo web in a security-disabled browser and it seems to work fine (with a patch to fix the above issue). It could be very close to get LD fully compatible with all platforms Expo support.

QuanGao-osmind commented 1 month ago

@yusinto @louis-launchdarkly Followup question, which SDK would you recommend us to use for Expo web?

In the documentation for React Web SDK, I see

The React Web SDK does not work in React Native projects
If you want to add LaunchDarkly to your React Native codebase, use the React Native SDK instead.

Do we need to resort to JavaScript SDK?

retronouns commented 1 month ago

My team just ran into this issue as well! ❤️

It's very useful to be able to run our apps in expo web during local development, so I am happy to see there is a ticket to address it, even if there is no ETA yet. 😄

retronouns commented 1 week ago

@QuanGao-osmind We ended up needing to use both the RN SDK and the JS SDK and have 2 implementations using platform specific modules: abcd.tsx that uses the RN SDK, and abcd.web.tsx that uses the JS SDK.

Definitely not ideal, but it appears to work.