react-native-launch-arguments icon indicating copy to clipboard operation
react-native-launch-arguments copied to clipboard

Empty set of launch arguments if used in a very early stage (Android)

Open d4vidi opened this issue 1 year ago • 10 comments

Hi, Detox maintainer here 👋🏻 I've recently been making usage of this library (great job, BTW!) in Detox's self-test project. We see that quite clearly, on Android at least, if the launch arguments are used in a very early stage (e.g. in the app's index.js), then intermittently, an empty arguments object is returned.

For example:

import React, {Component} from 'react';
import {
  AppRegistry,
} from 'react-native';
import { LaunchArguments } from 'react-native-launch-arguments';

console.warn('DEBUG', LaunchArguments.value());

export default class ExampleApp extends Component {
// ...
}

AppRegistry.registerComponent('example', () => ExampleApp);

If the app is repeatedly launched using device.launchApp({ launchArgs: { 'my': 'arg' } }), then you would see logs looking somewhere along the lines of:

DEBUG { my: arg }
DEBUG { my: arg }
DEBUG {}
DEBUG { my: arg }
DEBUG { my: arg }
DEBUG { my: arg }
DEBUG {}

Side note: I suppose there's a race condition here, sorting out the arguments into the NativeModule's constants.

d4vidi avatar Aug 18 '22 12:08 d4vidi

@iamolegga do you think there's a way to get this sorted out somehow? Perhaps Detox's implementation could provide a decent alternative, although asynchronous.

d4vidi avatar Aug 30 '22 13:08 d4vidi

@d4vidi sorry, I'm not able to investigate this in the nearest future. But I would be glad to merge fix for this. Maybe in the late 2022 I'll get back to this issue (and all the others) if on my current project we will use this lib

iamolegga avatar Aug 30 '22 16:08 iamolegga

I could provide a fix but best if you give a general approval 😄

d4vidi avatar Aug 30 '22 19:08 d4vidi

PR's are always welcome 🙂

iamolegga avatar Aug 31 '22 08:08 iamolegga

Perhaps Detox's implementation could provide a decent alternative, although asynchronous.

I meant, an approval of this, in particular.

d4vidi avatar Aug 31 '22 08:08 d4vidi

So you want to replace built-in method with the detox's one? Then we need to check that:

  • [ ] returned data is consistent between platforms
  • [ ] what about appium? maybe detect somehow which framework is installed and then chose the right method to resolve data.

Does getLaunchArguments mentioned in the detox's docs? If this is available for the end user then this library can be deprecated in favor of detox built-in method, right?

iamolegga avatar Aug 31 '22 09:08 iamolegga

It is not a Detox top-level API - Detox never runs inside the app. The Detox code I pointed at was of Detox's self-test app.

d4vidi avatar Sep 01 '22 08:09 d4vidi

The main question is whether you'd be willing to change the API in a breaking way, namely from:

import {LaunchArguments} from 'react-native-launch-arguments';
const args = LaunchArguments.values()

to something along the lines of:

import {  NativeModules } from 'react-native';
const { LaunchArguments } = NativeModules;
const args = await LaunchArguments.values();

d4vidi avatar Sep 01 '22 09:09 d4vidi

I believe we can do this inside index.js of this module:

import {  NativeModules } from 'react-native';
const { LaunchArguments } = NativeModules;
export { LaunchArguments }

then only asynchrony will changed, and from my point of view that's ok if the bug can be fixed only this way

iamolegga avatar Sep 01 '22 09:09 iamolegga

Cool

d4vidi avatar Sep 01 '22 09:09 d4vidi