onMessage is delaying
Bug description:
postMessage calls from a web page loaded in WebView are not consistently delivered to the onMessage handler on the React Native side in real time. The first few calls are received and logged immediately, but after a handful of clicks, a message is delayed and only shows up in the RN console significantly later than when it was actually sent from the WebView.
To Reproduce:
- Load a web page inside
WebViewthat has a button wired to callwindow.ReactNativeWebView.postMessage(...)with a JSON payload on click. - On the RN side, register an
onMessagehandler on theWebViewthat logs the received message with a timestamp. - Click the button repeatedly (roughly once every 1-2 seconds).
- Observe that the few clicks are logged immediately in the RN console.
- After some time, nothing is logged right away. After waiting, the message eventually appears in the log — but noticeably later than when the button was actually clicked.
Expected behavior:
Every postMessage call from the WebView should be delivered to onMessage on the RN side promptly and consistently, in the order it was sent, without an unexplained delay on some (but not all) messages.
Screenshots/Videos:
https://github.com/user-attachments/assets/7f7d9617-2702-4193-b0e5-c93c56bcce73
I have sent a message right after the modal appearing, but only receive the message after around 1 minute, can see around 1:15 of the screen record.
Environment:
- OS: Android
- OS version: 16
- react-native version: 0.74.3
- react-native-webview version: ^13.10.5
Source: react-native-webview/react-native-webview