mirror of
https://github.com/status-im/react-native.git
synced 2025-02-26 08:05:34 +00:00
Ensure WebViews render about:blank correctly
Summary: @public This diff fixes two bugs: 1. When you load a `<WebView/>` with an HTML source string, HTML source doesn't render in the `<WebView/>`. 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 `<WebView/>` (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
This commit is contained in:
parent
0f08635991
commit
a5ce1ad767
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user