From 442c918dea151c931a322ea1a590585862947694 Mon Sep 17 00:00:00 2001 From: Henry Heino Date: Sat, 21 Dec 2024 17:43:17 -0800 Subject: [PATCH 1/3] iOS: Work around webview reload bug --- .../app-mobile/components/ExtendedWebView/index.tsx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/app-mobile/components/ExtendedWebView/index.tsx b/packages/app-mobile/components/ExtendedWebView/index.tsx index 68279c5f0d5..5c5d26f7829 100644 --- a/packages/app-mobile/components/ExtendedWebView/index.tsx +++ b/packages/app-mobile/components/ExtendedWebView/index.tsx @@ -87,6 +87,14 @@ const ExtendedWebView = (props: Props, ref: Ref) => { return Setting.value('env') === 'dev' || (!!props.hasPluginScripts && Setting.value('plugins.enableWebviewDebugging')); }, [props.hasPluginScripts]); + const [reloadCounter, setReloadCounter] = useState(0); + const refreshWebView = useCallback(() => { + // Reload the WebView after a brief delay. See https://github.com/react-native-webview/react-native-webview/issues/3524 + shim.setTimeout(() => { + setReloadCounter(counter => counter + 1); + }, 150); + }, []); + // - `setSupportMultipleWindows` must be `true` for security reasons: // https://github.com/react-native-webview/react-native-webview/releases/tag/v11.0.0 @@ -99,6 +107,7 @@ const ExtendedWebView = (props: Props, ref: Ref) => { // (the default deaccelerates too quickly). return ( ) => { onMessage={props.onMessage} onError={props.onError ?? onError} onLoadEnd={props.onLoadEnd} + onContentProcessDidTerminate={refreshWebView} + onRenderProcessGone={refreshWebView} decelerationRate='normal' /> ); From 2a669b9aa26d11a18cffe632a9e7b4cc82c188cd Mon Sep 17 00:00:00 2001 From: Henry Heino Date: Mon, 23 Dec 2024 11:11:00 -0800 Subject: [PATCH 2/3] Refactoring, logging --- .../app-mobile/components/ExtendedWebView/index.tsx | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/app-mobile/components/ExtendedWebView/index.tsx b/packages/app-mobile/components/ExtendedWebView/index.tsx index 5c5d26f7829..7654f0031b2 100644 --- a/packages/app-mobile/components/ExtendedWebView/index.tsx +++ b/packages/app-mobile/components/ExtendedWebView/index.tsx @@ -88,11 +88,10 @@ const ExtendedWebView = (props: Props, ref: Ref) => { }, [props.hasPluginScripts]); const [reloadCounter, setReloadCounter] = useState(0); - const refreshWebView = useCallback(() => { - // Reload the WebView after a brief delay. See https://github.com/react-native-webview/react-native-webview/issues/3524 - shim.setTimeout(() => { - setReloadCounter(counter => counter + 1); - }, 150); + 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...'); + setReloadCounter(counter => counter + 1); }, []); // - `setSupportMultipleWindows` must be `true` for security reasons: @@ -132,8 +131,8 @@ const ExtendedWebView = (props: Props, ref: Ref) => { onMessage={props.onMessage} onError={props.onError ?? onError} onLoadEnd={props.onLoadEnd} - onContentProcessDidTerminate={refreshWebView} - onRenderProcessGone={refreshWebView} + onContentProcessDidTerminate={refreshWebViewAfterCrash} + onRenderProcessGone={refreshWebViewAfterCrash} decelerationRate='normal' /> ); From 5558a395934dead07b685c209cd52406744a4a77 Mon Sep 17 00:00:00 2001 From: Henry Heino Date: Mon, 23 Dec 2024 11:18:01 -0800 Subject: [PATCH 3/3] Restore the setTimeout, add comments --- packages/app-mobile/components/ExtendedWebView/index.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/app-mobile/components/ExtendedWebView/index.tsx b/packages/app-mobile/components/ExtendedWebView/index.tsx index 7654f0031b2..e5ff0e2709c 100644 --- a/packages/app-mobile/components/ExtendedWebView/index.tsx +++ b/packages/app-mobile/components/ExtendedWebView/index.tsx @@ -91,7 +91,11 @@ const ExtendedWebView = (props: Props, ref: Ref) => { 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...'); - setReloadCounter(counter => counter + 1); + 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: