react / react/react-native

[Android] Timing of NativeCommands delivery vs. calls of TurboModule methods vs. AppState changes

Aperta
#45,017 7 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Needs: Attention Never gets stale Platform: Android Type: New Architecture
Lingua principale
C++
Stelle
127k
Fork
25.3k
Merge medio
1g 23h
PR unite (30g)
4

Descrizione

Description

Not sure, is it a bug, or a peculiarity of the new architecture, but here is my scenario. My app uses RN 0.74.2, with new arch, bridgeless. It has an internal web server (my @dr.pogodin/react-native-static-server — a TurboModule), and it has a WebView (my slightly enhanced fork of react-native-webview — a Fabric component), which loads assets from that web server. When the app goes into background I want to abort any in-flight loading by RN WebView, and then shutdown the server. To do so, I listen for AppState change, and when the state changes to background I call RN WebView's stopLoading() method, and my server's stop() command; both calls are passed to the native side, via Fabric's NativeCommand in WebView case, and via TurboModule method call in my server's case.

Now I am testing it on Android, with a bunch of debug logging, and native debugger at hands. I see the following:

  • I send my app to the background.
  • Both WebView's stopLoading() and server's stop() are called in JS layer.
  • The server's TurboModule stop() operation is successfully executed in the native layer, and it even manages to emit back a notification that server stopped (using RCTDeviceEventEmitter) so that in JS layer a message is printed to the console that server successfully stopped.
  • However; the WebViews stopLoading() command is not triggered at the native side — not until the app is brought back to the foreground again, immediately after which I capture by the debugger that it has been triggered.

My expectation here, especially considering that TurboModule has no problem to trigger native call, and deliver backward event to JS immediately after the app state changed to background, that the same should work for Fabric components; however, it is not the case. What do you think? Is it a bug? Or a limitation of the current new arch implementation for components? Or is it RN WebView's code uses a stale approach to operate native commands (though, it seems it follows what is currently documented here)?

Steps to reproduce

N/A

React Native Version

0.74.2

Affected Platforms

Runtime - Android

Areas

Other (please specify)

Output of npx react-native info
N/A
Stacktrace or Logs
N/A
Reproducer

https://github.com/birdofpreyru/issue-45017

Screenshots and Videos

No response

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con il reproducer collegato all’indirizzo https://github.com/birdofpreyru/issue-45017 e traccia i percorsi di distribuzione Android per Fabric NativeCommands, le chiamate a TurboModule e le modifiche di AppState. Confronta la chiamata stopLoading() di WebView con la chiamata stop() del server; il lavoro è completato quando il comportamento relativo all’ordine o al blocco è spiegato e il comportamento previsto è stabilito chiaramente.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
android, javascript, react-native
Ambito
mobile-dev
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
28/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.