[Android] Timing of NativeCommands delivery vs. calls of TurboModule methods vs. AppState changes
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 127k
- Forks
- 25.3k
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 4
Description
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'sstop()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 (usingRCTDeviceEventEmitter) 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked reproducer at https://github.com/birdofpreyru/issue-45017 and trace the Android delivery paths for Fabric NativeCommands, TurboModule calls, and AppState changes. Compare the WebView stopLoading() call with the server stop() call; done means the ordering or blocking behavior is explained and the expected behavior is clearly established.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, javascript, react-native
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 28/100