react / react/react-native

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

Offen
#45,017 7 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Needs: Attention Never gets stale Platform: Android Type: New Architecture
Vorherrschende Sprache
C++
Sterne
127k
Forks
25.3k
Ø Merge
1 T. 23 Std.
Gemergte PRs (30 T.)
4

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit dem verknüpften Reproducer unter https://github.com/birdofpreyru/issue-45017 und verfolge die Android-Zustellpfade für Fabric NativeCommands, TurboModule-Aufrufe und AppState-Änderungen. Vergleiche den WebView-Aufruf stopLoading() mit dem Server-Aufruf stop(); als abgeschlossen gilt die Untersuchung, wenn das Reihenfolge- oder Blockierungsverhalten erklärt und das erwartete Verhalten eindeutig festgestellt ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
android, javascript, react-native
Bereich
mobile-dev
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
28/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.