question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

onContentProcessDidTerminate not called in newer versions of react-native-webview + react-native

See original GitHub issue

Thanks 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:

  1. Create a fresh react-native project following instructions: https://reactnative.dev/docs/environment-setup i.e.
npx react-native init AwesomeProject
  1. Install react-native-webview via npm + update pods

  2. Import into App.js WebView

import { WebView } from 'react-native-webview';
  1. 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>
  );
  1. Run on device from xcode as per: https://reactnative.dev/docs/running-on-device

  2. 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:closed
  • Created a year ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
moonsiftcommented, Jul 3, 2022

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.

2reactions
react-native-community-botcommented, Jul 6, 2022

🎉 This issue has been resolved in version 11.22.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

Read more comments on GitHub >

github_iconTop Results From Across the Web

react native Webview Process Terminated - Stack Overflow
This happens on iOS if the WebView is using too many resources, and results in either the WebView crashing (showing a blank white...
Read more >
reason-react-native/webview - npm.io
Specifies function to be invoked when the WebView content process is terminated. The process may be terminated due to reasons such as running...
Read more >
docs/Reference.md · Mar-er/react-native-webview - Gitee.com
Function that is invoked when the WebView content process is terminated. Type, Required, Platform. function, No, iOS WKWebView. Example:.
Read more >
WebView - React Native
This is documentation for React Native 0.63, which is no longer actively maintained. For up-to-date documentation, see the latest version (0.70) ...
Read more >
How to handle navigation with WebViews in a React Native app
For Android users, if you're using the latest react-native-webview version (which you are) open the file android/gradle.properties and make sure the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found