Skip to content
This repository was archived by the owner on Apr 7, 2026. It is now read-only.

fix(android): fix headless crash with null ReactContext#1168

Merged
mikehardy merged 5 commits into
mainfrom
@mikehardy/fix-another-headless-crash
Dec 16, 2024
Merged

fix(android): fix headless crash with null ReactContext#1168
mikehardy merged 5 commits into
mainfrom
@mikehardy/fix-another-headless-crash

Conversation

@mikehardy

Copy link
Copy Markdown
Collaborator

very tricky to make sure react-native is initialized during headlessJS startup so you don't beat it in the race to asking for a ReactContext before it exists

  • startup is event-driven so you have to attach listeners
  • startup has to run on main thread so you have to post runnables
  • multiple tasks may come in while starting up, you must queue / drain
  • startup objects / methods differ across react-native new / old arch

get all that right, and you'll have a valid ReactContext, without dropping any tasks that needed it before react-native was initialized

Previously, we were attempting to use a null ReactContext, resulting in errors from upstream headless services complaining about the context already being destroyed

Fixes #266

very tricky to make sure react-native is initialized during
headlessJS startup so you don't beat it in the race to asking
for a ReactContext before it exists

- startup is event-driven so you have to attach listeners
- startup has to run on main thread so you have to post runnables
- multiple tasks may come in while starting up, you must queue / drain
- startup objects / methods differ across react-native new / old arch

get all that right, and you'll have a valid ReactContext, without
dropping any tasks that needed it before react-native was initialized
@mikehardy mikehardy added the pending-merge Waiting on CI or question responses to merge, but otherwise ready label Dec 15, 2024
@codecov

codecov Bot commented Dec 15, 2024

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.08%. Comparing base (77e72bd) to head (29a0745).
Report is 5 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1168   +/-   ##
=======================================
  Coverage   77.08%   77.08%           
=======================================
  Files          32       32           
  Lines        1727     1727           
  Branches      556      556           
=======================================
  Hits         1331     1331           
  Misses        395      395           
  Partials        1        1           

otherwise react-native complains a lot in the log
now there is a button that will create a trigger notification
for +15 secs, allowing time to kill the app. Then a background
handler should tell you that you got a notification in the background
this should have been in index.js so it could be registered as
a background handler prior to AppRegistry registration of the app
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

1 participant