Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is the future of Headless JS? #45731

Closed
kross-italk opened this issue Jul 26, 2024 · 6 comments
Closed

What is the future of Headless JS? #45731

kross-italk opened this issue Jul 26, 2024 · 6 comments
Labels
Resolution: Answered When the issue is resolved with a simple answer

Comments

@kross-italk
Copy link

Description

After going through the implementation, HeadlessJS is poorly advertised. By its name sake, one would expect "Headless" and "Background" to be synonmous. That doesn't appear to be the case:

#15915
#27835
#43950
#36493

Headless JS tasks have to be started from the Main UI thread, and when the app is put in the background (but left running) the tasks stop. This is next to useless, I could always have asyncrously scheduled my jobs in the main JS conext while the app was forgrounded. The very existence of the "Crash in foreground" being the default suggests this isn't going to be considered.

The documentation was very rough and I had to cobble together various open source repos that demonstrate using it.

How is one expected to make a real background service using Headless JS? Is there any future to this code, or has it gone stale?

Steps to reproduce

  1. install react-native
  2. Kotin: applicationContext.startService(service)
  3. Background the app by sliding it up and picking another app
  4. All JS activity is stopped, network requests, timers, the whole JS context is evicted.

React Native Version

0.73.6

Affected Platforms

Runtime - Android

Output of npx react-native info

root@836c7ff65b76:/usr/src/app# npm info
npm notice
npm notice New minor version of npm available! 10.7.0 -> 10.8.2
npm notice Changelog: https://github.com/npm/cli/releases/tag/v10.8.2
npm notice To update run: npm install -g npm@10.8.2
npm notice
npm error code E404
npm error 404 Not Found - GET https://registry.npmjs.org/- Not found
npm error 404
npm error 404  '@*' is not in this registry.
npm error 404
npm error 404 Note that you can also install from a
npm error 404 tarball, folder, http url, or git url.

npm error A complete log of this run can be found in: /root/.npm/_logs/2024-07-26T13_08_10_383Z-debug-0.log
root@836c7ff65b76:/usr/src/app# ^C
root@836c7ff65b76:/usr/src/app# exit
exit

Stacktrace or Logs

If you specify "Allow to run in foregound" the headless service works until backgrounded.
Otherwise the application crashes.

Reproducer

Screenshots and Videos

No response

@react-native-bot
Copy link
Collaborator

⚠️ Newer Version of React Native is Available!
ℹ️ You are on a supported minor version, but it looks like there's a newer patch available - 0.73.9. Please upgrade to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases.

@react-native-bot react-native-bot added Needs: Author Feedback Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. labels Jul 26, 2024
@react-native-bot
Copy link
Collaborator

⚠️ Missing Reproducible Example
ℹ️ We could not detect a reproducible example in your issue report. Please provide either:
  • If your bug is UI related: a Snack
  • If your bug is build/update related: use our Reproducer Template. A reproducer needs to be in a GitHub repository under your username.

@react-native-bot
Copy link
Collaborator

⚠️ Missing Reproducible Example
ℹ️ We could not detect a reproducible example in your issue report. Please provide either:

@react-native-bot
Copy link
Collaborator

⚠️ Newer Version of React Native is Available!
ℹ️ You are on a supported minor version, but it looks like there's a newer patch available - undefined. Please upgrade to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases.

@kross-italk
Copy link
Author

And listen, pushing everyone in the community away with an auto-close bot isn't helping.

@github-actions github-actions bot added Needs: Attention Issues where the author has responded to feedback. and removed Needs: Author Feedback labels Jul 26, 2024
@cortinico
Copy link
Contributor

And listen, pushing everyone in the community away with an auto-close bot isn't helping.

That's because this is an issue tracker only. It's not the right spot for questions/discussions. The best place is here https://github.com/react-native-community/discussions-and-proposals (there is even a button in https://github.com/facebook/react-native/issues/new/choose).

To answer your question: we'll most likely deprecate and remove Headless JS in a future version. We'll open a discussion in the coming months to collect community feedback from it, but the reality is that is not an API we'd recommend.

We're not using it internally at Meta, and it's backed by an Android Service which is a bad choice in 2024 for background execution.
The documentation should also be updated to mention to don't use this API anymore.

The alternative would be to update Headless JS API to depend on WorkManager or JobScheduler but we don't have capacity at the moment to do this work. A community contribution would be more than welcome in this sense.

@cortinico cortinico added Resolution: Answered When the issue is resolved with a simple answer and removed Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Newer Patch Available Needs: Attention Issues where the author has responded to feedback. labels Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Answered When the issue is resolved with a simple answer
Projects
None yet
Development

No branches or pull requests

3 participants