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 3 years 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

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

Is this fixed? We have this problem as well that is fails on Android.

richardruiter avatar Dec 12 '22 13:12 richardruiter

Been happening to me as well, Android only

PinhoL avatar Apr 03 '23 13:04 PinhoL

Now actively trying to get this fixed

d4vidi avatar May 16 '23 13:05 d4vidi

Still researching. This is what I've done so far: https://github.com/wix/Detox/pull/4060

d4vidi avatar May 17 '23 10:05 d4vidi

Here are the full details: https://github.com/facebook/react-native/issues/37518

d4vidi avatar May 23 '23 14:05 d4vidi

Should be fixed in #72 by @d4vidi

Please try npm i react-native-launch-arguments@next and comment here if it works correctly, I'll publish it as a new major release then.

iamolegga avatar May 25 '23 06:05 iamolegga

Should be fixed in #72 by @d4vidi

Please try npm i react-native-launch-arguments@next and comment here if it works correctly, I'll publish it as a new major release then.

Great, thank you. I'll integrate that back into the Detox self-test app, we'll see how it goes.

d4vidi avatar May 25 '23 09:05 d4vidi

Seems like the problem hasn't been resolved, according to Detox: There is a still another subtle update required: #73.

d4vidi avatar May 28 '23 13:05 d4vidi

@d4vidi I've just published 4.0.0-rc.1. Please try again npm i react-native-launch-arguments@next

iamolegga avatar May 29 '23 08:05 iamolegga

Thanks!

d4vidi avatar May 29 '23 09:05 d4vidi

@iamolegga things are looking stable on the Detox side (https://github.com/wix/Detox/pull/4060) 👍🏻 LMK when you have an official release so we can get off the next tag

d4vidi avatar May 29 '23 11:05 d4vidi

@d4vidi done ✅

iamolegga avatar May 30 '23 08:05 iamolegga