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

iOS: Fixes #11544: Fix blank screen on bringing app from background #11555

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/app-mobile/components/ExtendedWebView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,17 @@ const ExtendedWebView = (props: Props, ref: Ref<WebViewControl>) => {
return Setting.value('env') === 'dev' || (!!props.hasPluginScripts && Setting.value('plugins.enableWebviewDebugging'));
}, [props.hasPluginScripts]);

const [reloadCounter, setReloadCounter] = useState(0);
const refreshWebViewAfterCrash = useCallback(() => {
// Reload the WebView on crash. See https://github.com/react-native-webview/react-native-webview/issues/3524
logger.warn('Content process lost. Reloading the webview...');
shim.setTimeout(() => {
setReloadCounter(counter => counter + 1);
// Restart after a brief delay to mitigate the case where the crash is due to
// an out-of-memory or content script bug.
}, 250);
}, []);

// - `setSupportMultipleWindows` must be `true` for security reasons:
// https://github.com/react-native-webview/react-native-webview/releases/tag/v11.0.0

Expand All @@ -99,6 +110,7 @@ const ExtendedWebView = (props: Props, ref: Ref<WebViewControl>) => {
// (the default deaccelerates too quickly).
return (
<WebView
key={`webview-${reloadCounter}`}
style={{
// `backgroundColor: transparent` prevents a white fhash on iOS.
// It seems that `backgroundColor: theme.backgroundColor` does not
Expand All @@ -123,6 +135,8 @@ const ExtendedWebView = (props: Props, ref: Ref<WebViewControl>) => {
onMessage={props.onMessage}
onError={props.onError ?? onError}
onLoadEnd={props.onLoadEnd}
onContentProcessDidTerminate={refreshWebViewAfterCrash}
onRenderProcessGone={refreshWebViewAfterCrash}
decelerationRate='normal'
/>
);
Expand Down
Loading