react / react/react-native

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

オープン
#45,017 コメント 7 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Needs: Attention Never gets stale Platform: Android Type: New Architecture
主要言語
C++
スター
127k
フォーク
25.3k
平均マージ
1日 23時間
マージ済み PR(30日)
4

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

https://github.com/birdofpreyru/issue-45017 のリンク先の reproducer から始め、Fabric NativeCommands、TurboModule 呼び出し、AppState の変更に関する Android の配信経路を追跡します。WebView の stopLoading() 呼び出しとサーバーの stop() 呼び出しを比較します。順序またはブロッキングの挙動が説明され、期待される挙動が明確に確立されれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
android, javascript, react-native
領域
mobile-dev
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
28/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。