React-native: WebView onLoadEnd never get call (iOS)

Created on 11 Apr 2018  路  11Comments  路  Source: facebook/react-native

Environment

Environment:
OS: macOS High Sierra 10.13.3
Node: 8.9.4
Yarn: 1.5.1
npm: 5.6.0
Watchman: 4.9.0
Xcode: Xcode 9.2 Build version 9C40b
Android Studio: 3.0 AI-171.4443003

Packages: (wanted => installed)
react: 16.3.0-alpha.1 => 16.3.0-alpha.1
react-native: 0.54.0 => 0.54.0

Steps to Reproduce

import React from "react";
import { StyleSheet, Text, View, WebView } from "react-native";

export default class App extends React.Component {
  render() {
    return (
      <WebView
        source={{ html: "<h1>Hello World<h1>" }}
        onLoadEnd={e => console.log("end", e)}
        onLoadStart={e => console.log("start", e)}
        onError={e => console.log("error", e)}
      />
    );
  }
}

Snack

Expected Behavior


It should both log start and end.

Actual Behavior


Only start event is logged.

WebView iOS Locked

Most helpful comment

When you use WebView with source={{ html }} the url is about:blank.

InRCTWebView.m:346 we have ![webView.request.URL.absoluteString isEqualToString:@"about:blank"]:

// we only need the final 'finishLoad' call so only fire the event when we're actually done loading.
  else if (_onLoadingFinish && !webView.loading && ![webView.request.URL.absoluteString isEqualToString:@"about:blank"]) {
  _onLoadingFinish([self baseEvent]);
}

Setting an empty url in WebView's source fixes this issue:

<WebView
  source={{ html: `<h1>Hello World<h1>`, baseUrl: '' }}
  onLoadEnd={e => console.log('end', e)}
  onLoadStart={e => console.log('start', e)}
  onError={e => console.log('error', e)}
  />

All 11 comments

Thanks for posting this! It looks like your issue may refer to an older version of React Native. Can you reproduce the issue on the latest release, v0.55?

Thank you for your contributions.

@react-native-bot yes

I can confirm this issue

i can confirm issue too

i can confirm issue too, android platform

When you use WebView with source={{ html }} the url is about:blank.

InRCTWebView.m:346 we have ![webView.request.URL.absoluteString isEqualToString:@"about:blank"]:

// we only need the final 'finishLoad' call so only fire the event when we're actually done loading.
  else if (_onLoadingFinish && !webView.loading && ![webView.request.URL.absoluteString isEqualToString:@"about:blank"]) {
  _onLoadingFinish([self baseEvent]);
}

Setting an empty url in WebView's source fixes this issue:

<WebView
  source={{ html: `<h1>Hello World<h1>`, baseUrl: '' }}
  onLoadEnd={e => console.log('end', e)}
  onLoadStart={e => console.log('start', e)}
  onError={e => console.log('error', e)}
  />

you have solved my problem

v0.56.0
baseUrl not work.

This issue will solve when RN use WKWebView instead of UIWebView.
https://github.com/facebook/react-native/issues/321

I'm not planning to migrate this issue to https://github.com/react-native-community/react-native-webview as @soyanakagawa indicated that using WKWebView will fix it, and we're defaulting to WKWebView over there. If you want, you can try that package and see if your issues are resolved. If so, we could probably close this issue.

There has been no further interaction here so I feel safe in closing per comment above

v0.56.0
baseUrl not work.

This issue will solve when RN use WKWebView instead of UIWebView.

321

this works for me, thanks

Was this page helpful?
0 / 5 - 0 ratings