From 692493bff8fecab7e916f678c4606bfdbecd260e Mon Sep 17 00:00:00 2001 From: Ramanpreet Nara Date: Mon, 13 Aug 2018 10:14:06 -0700 Subject: [PATCH] Ensure WebViews render about:blank correctly Summary: @public This diff fixes two bugs: 1. When you load a `` with an HTML source string, HTML source doesn't render in the ``. Instead, we get this warning: https://pxl.cl/grz3. Here's what the above page should look like when correctly rendered: https://pxl.cl/grzt 2. Furthermore, you render a blank `` (i.e: with no source prop), it should display a blank page. Instead, we get this warning: https://pxl.cl/grz3 **Bugfix:** One solution I found was to ensure that `about:blank` is always whitelisted. That way, we don't ever abort navigations to blank pages, which occur when we do: ```ObjectiveC /** Line 134 in RCTWebView.m */ [_webView loadHTMLString:@"" baseURL:nil]; ``` and ```ObjectiveC /** Line 115 in RCTWebView.m */ if (html) { NSURL *baseURL = [RCTConvert NSURL:source[@"baseUrl"]]; if (!baseURL) { baseURL = [NSURL URLWithString:@"about:blank"]; } [_webView loadHTMLString:html baseURL:baseURL]; return; } ``` Reviewed By: yungsters, mmmulani Differential Revision: D9259852 fbshipit-source-id: e1b9673fcd8c3d0df77308df8c4a632a2b596bfb --- Libraries/Components/WebView/WebView.ios.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Libraries/Components/WebView/WebView.ios.js b/Libraries/Components/WebView/WebView.ios.js index 56290df97bc..413cae03950 100644 --- a/Libraries/Components/WebView/WebView.ios.js +++ b/Libraries/Components/WebView/WebView.ios.js @@ -435,9 +435,10 @@ class WebView extends React.Component { const viewManager = nativeConfig.viewManager || RCTWebViewManager; - const compiledWhitelist = (this.props.originWhitelist || []).map( - WebViewShared.originWhitelistToRegex, - ); + const compiledWhitelist = [ + 'about:blank', + ...(this.props.originWhitelist || []), + ].map(WebViewShared.originWhitelistToRegex); const onShouldStartLoadWithRequest = (event: Event) => { let shouldStart = true; const {url} = event.nativeEvent;