Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Underlying WKWebView instance is not disposed of after unmounting WebView component #22067

Closed
3 tasks done
jacamera opened this issue Nov 1, 2018 · 3 comments
Closed
3 tasks done
Labels
Component: View Component: WebView Related to the WebView component. Resolution: Locked This issue was locked by the bot.

Comments

@jacamera
Copy link

jacamera commented Nov 1, 2018

Environment

React Native Environment Info:
System:
  OS: macOS High Sierra 10.13.6
  CPU: x64 Intel(R) Core(TM) i7-4750HQ CPU @ 2.00GHz
  Memory: 82.27 MB / 8.00 GB
  Shell: 3.2.57 - /bin/bash
Binaries:
  Node: 8.11.3 - /usr/local/bin/node
  npm: 5.6.0 - /usr/local/bin/npm
SDKs:
  iOS SDK:
    Platforms: iOS 12.0, macOS 10.14, tvOS 12.0, watchOS 5.0
IDEs:
  Xcode: 10.0/10A255 - /usr/bin/xcodebuild
npmPackages:
  react: 16.6.0-alpha.8af6728 => 16.6.0-alpha.8af6728
  react-native: 0.57.4 => 0.57.4
npmGlobalPackages:
  react-native-cli: 2.0.1
  react-native-git-upgrade: 0.2.7

Description

When the useWebKit prop is set on the WebView component the underlying WKWebView instance does not get disposed of after the component is unmounted. These lingering instances can be seen using the Develop menu in Safari. This is only a problem when the useWebKit prop is set.

Reproducible Demo

  1. Run the following code using react-native run-ios from the repository or by copy/pasting into App.js in a newly initialized React Native project.
  2. Launch Safari and verify that you can see JSContext running in the simulator.
  3. Click the 'Toggle WebView' button to mount and unmount the WebView component.
  4. Verify that the unmounted WKWebView instances are still active and accessible via Safari.
  5. Remove the useWebKit prop and re-run to verify this only happens when that prop is set.

Repository: https://github.com/jacamera/rnWebviewTest

App.js:

import React, {Component} from 'react';
import {View, Button, WebView} from 'react-native';

type Props = {};
export default class App extends Component<Props> {
  constructor(props) {
    super(props);
    this.state = { showWebView: false };
    this._toggleWebView = () => {
      this.setState(prevState => ({ showWebView: !prevState.showWebView }));
    };
  }
  render() {
    return (
      <View style={{ flex: 1, padding: 50 }}>
        <Button
          onPress={this._toggleWebView}
          title="Toggle WebView"
        />
        {this.state.showWebView ?
          <WebView
            source={{ uri: 'https://www.google.com' }}
            useWebKit
          /> :
          null}
      </View>
    );
  }
}

Screenshot:
screen shot 2018-11-01 at 12 51 15 pm

@bartolkaruza
Copy link

Have you tried this with the separate react-native-webview ? It looks like that's where more improvements for the Webview component land (faster) and the current one will be removed from the core at some point, according to this approved proposal. You can see the full discussion here.

@jacamera
Copy link
Author

jacamera commented Nov 2, 2018

@bartolkaruza Thank you for bringing this to my attention. I had fallen back to using https://github.com/CRAlpha/react-native-wkwebview since there was no mention of the separate WebView package in the docs. I just tested it and the separate react-native-webview disposes of the WebView instances properly so it's just an issue with the built-in component.

I feel like this issue should still be left open though since this seems like a pretty serious memory leak and there isn't any indication from the docs or console output that the built-in WebView component shouldn't be used.

@hramos
Copy link
Contributor

hramos commented Nov 30, 2018

Please file an issue over at https://github.com/react-native-community/react-native-webview. The webview in this repository will be removed in a future version, and no WebView PRs are being merged on this repository.

@hramos hramos closed this as completed Nov 30, 2018
@facebook facebook locked as resolved and limited conversation to collaborators Nov 30, 2019
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Nov 30, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Component: View Component: WebView Related to the WebView component. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

4 participants