onContentProcessDidTerminate not called in newer versions of react-native-webview + react-native
See original GitHub issueThanks for making this library, here is my first bug report
Bug description: I recently upgraded some of our packages, and noticed that the callback given to onContentProcessDidTerminate was no longer being called. However, react-native-webview was detecting that the webview had terminated. We use this callback to reload the webview if it is terminated due to OS memory constraints.
To Reproduce:
- Create a fresh react-native project following instructions: https://reactnative.dev/docs/environment-setup i.e.
npx react-native init AwesomeProject
-
Install react-native-webview via npm + update pods
-
Import into App.js WebView
import { WebView } from 'react-native-webview';
- Replace App.js rendering code with:
return (
<SafeAreaView style={{ flex: 1 }}>
<WebView
source={{ uri: 'https://google.com' }}
onContentProcessDidTerminate={(event)=>{console.log("END OF A WEBVIEW!")}}
/>
</SafeAreaView>
);
-
Run on device from xcode as per: https://reactnative.dev/docs/running-on-device
-
Trigger webViewWebContentProcessDidTerminate. For example, by opening and refreshing many high-memory websites in Safari. (If anyone knows of an easier and more reliable way to trigger this please let me know)
Result: No console message “END OF A WEBVIEW!”
Expected behavior: onContentProcessDidTerminate, as provided in the react component property, is called.
Environments: This occurs for me on: node version: 16.15.1 react-native: 0.67.1 react-native-webview: 11.22.3
node version: 18.4.0 react-native: 0.69.0 react-native-webview: 11.22.3
node version: 16.15.1 react-native: 0.68.2 react-native-webview: 11.22.2
All using on-device development build + run from xcode: xcode: 13.4.1 ios: 15.5 device: ipad 6th generation MR7J2B/A
The lack of auto-restart of the webview was also reported by users of our main app via test flight.
The issue does NOT occur for the following configuration (it runs successfully): node version: 16.15.1 react-native: 0.67.1 react-native-webview: 11.6.4
Further investigations:
Further investigation proceeded with the following ‘hack’:
Adding the onScroll
callback to the WebView component as follows in App.js
onScroll={(event)=>{console.log("SCROLL!")}}
Then modifying node_modules/react-native-webview/apple/RNCWebView.m
such that we disable the _onScroll(event);
event at line 882 in the scrollViewDidScroll
method. And finally add the _onScroll(event);
back in after _onContentProcessDidTerminate(event);
on line 1186 in webViewWebContentProcessDidTerminate
.
In this case, the onScroll
callback fired on termination but still not onContentProcessDidTerminate. This demonstrates that the _onContentProcessDidTerminate
method exists (confirmed by the. debugger) and that the event can flow into the react-native component via onScroll, but not for onContentProcessDidTerminate!
Request: My current thoughts are that this is something to do with react-native’s upgrade limiting the props that can be called from the C function. I would appreciate if anyone else can confirm they are experiencing this issue. I’m not at all well versed in C or how react-native interacts with the C functions, so any suggestions on that front would be greatly appreciated.
For now we plan to downgrade react-native-webview to version 11.13.0
Issue Analytics
- State:
- Created a year ago
- Comments:8 (1 by maintainers)
Top GitHub Comments
I’ve taken a look at the code and think I see the problem now so I am happy to give fixing this a go.
🎉 This issue has been resolved in version 11.22.5 🎉
The release is available on:
Your semantic-release bot 📦🚀