react / react/react-native

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

Đang mở
#45,017 7 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Needs: Attention Never gets stale Platform: Android Type: New Architecture
Ngôn ngữ chính
C++
Star
127k
Fork
25.3k
Merge trung bình
1 ngày 23 giờ
Pull request đã merge (30 ngày)
4

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với reproducer được liên kết tại https://github.com/birdofpreyru/issue-45017 và theo dõi các đường dẫn phân phối Android cho Fabric NativeCommands, các lệnh gọi TurboModule và các thay đổi AppState. So sánh lệnh gọi stopLoading() của WebView với lệnh gọi stop() của máy chủ; được xem là hoàn tất khi hành vi về thứ tự hoặc chặn đã được giải thích và hành vi mong đợi đã được xác lập rõ ràng.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
android, javascript, react-native
Lĩnh vực
mobile-dev
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
28/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.