meliorence / react-native-render-html

iOS/Android pure javascript react-native component that renders your HTML into 100% native views
https://meliorence.github.io/react-native-render-html/
BSD 2-Clause "Simplified" License
3.48k stars 588 forks source link

Android crash while navigating back to stack screen . #393

Closed drb1 closed 4 years ago

drb1 commented 4 years ago

Oath

I swear that I have completed these tasks before submitting:

Decision table

Bug Report

07-29 17:41:49.173  6901  6901 F crashpad: dlopen: dlopen failed: library "libandroidicu.so" not found: needed by /system/lib/libharfbuzz_ng.so in namespace (default)
--------- beginning of crash
07-29 17:41:49.176  6410  6441 F libc    : Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x1c in tid 6441 (RenderThread), pid 6410 (com.newmednav)
07-29 17:41:49.340  6904  6904 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
07-29 17:41:49.340  6904  6904 F DEBUG   : Build fingerprint: 'google/sdk_gphone_x86_arm/generic_x86_arm:11/RPB2.200611.009/6625208:userdebug/dev-keys'
07-29 17:41:49.340  6904  6904 F DEBUG   : Revision: '0'
07-29 17:41:49.340  6904  6904 F DEBUG   : ABI: 'x86'
07-29 17:41:49.340  6904  6904 F DEBUG   : Timestamp: 2020-07-29 17:41:49+0545
07-29 17:41:49.340  6904  6904 F DEBUG   : pid: 6410, tid: 6441, name: RenderThread  >>> com.newmednav <<<
07-29 17:41:49.340  6904  6904 F DEBUG   : uid: 10152
07-29 17:41:49.340  6904  6904 F DEBUG   : signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x1c
07-29 17:41:49.340  6904  6904 F DEBUG   : Cause: null pointer dereference
07-29 17:41:49.340  6904  6904 F DEBUG   :     eax efbc2cb0  ebx eed5c69c  ecx eed52a80  edx 00000000
07-29 17:41:49.341  6904  6904 F DEBUG   :     edi d139ae90  esi 00000000
07-29 17:41:49.341  6904  6904 F DEBUG   :     ebp c086ed48  esp c086eb50  eip ee698c1c
07-29 17:41:49.425  6904  6904 F DEBUG   : backtrace:
07-29 17:41:49.425  6904  6904 F DEBUG   :       #00 pc 00247c1c  /system/lib/libhwui.so (android::uirenderer::skiapipeline::GLFunctorDrawable::onDraw(SkCanvas*)+1548) (BuildId: 434a9b68672e1dd2b15599730362463d)
07-29 17:41:49.425  6904  6904 F DEBUG   :       #01 pc 00303a57  /system/lib/libhwui.so (SkDrawable::draw(SkCanvas*, SkMatrix const*)+87) (BuildId: 434a9b68672e1dd2b15599730362463d)
07-29 17:41:49.425  6904  6904 F DEBUG   :       #02 pc 002f4606  /system/lib/libhwui.so (SkBaseDevice::drawDrawable(SkDrawable*, SkMatrix const*, SkCanvas*)+38) (BuildId: 434a9b68672e1dd2b15599730362463d)
07-29 17:41:49.425  6904  6904 F DEBUG   :       #03 pc 00659291  /system/lib/libhwui.so (SkGpuDevice::drawDrawable(SkDrawable*, SkMatrix const*, SkCanvas*)+353) (BuildId: 434a9b68672e1dd2b15599730362463d)
07-29 17:41:49.425  6904  6904 F DEBUG   :       #04 pc 002d9dc0  /system/lib/libhwui.so (SkCanvas::onDrawDrawable(SkDrawable*, SkMatrix const*)+48) (BuildId: 434a9b68672e1dd2b15599730362463d)
React Native

0.61.5

Libraries

Devices

Description

1.Android app crashes while navigating back to stack screen after rendering table content and embedded videos from youtube. 2.Normal behavior when rendering normal html content 3.No crashes while disable {enableScreen } from react-native-screens

jsamr commented 4 years ago

@drb1 Thank your for your report! Can you try out version 4.2.3-beta.1? (see #390 for instructions) There is an "enhancement" that might actually be a fix

HTML: use a proxy method setStateSafe to avoid updating while unmounted.

drb1 commented 4 years ago

this is minimal repo for analysis https://github.com/drb1/DemoForVideoCrashHtml

jsamr commented 4 years ago

@drb1 First of all, congratulations on the reproduction. That is pristine! So I did my little investigation, and this is what I found out:

diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index 433c7e2..c569e8f 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -15,6 +15,7 @@
         android:label="@string/app_name"
         android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
         android:launchMode="singleTask"
+        android:hardwareAccelerated="false"
         android:windowSoftInputMode="adjustResize">
         <intent-filter>
             <action android:name="android.intent.action.MAIN" />

Indeed, after disabling hardware acceleration, the app doesn't crash anymore.

drb1 commented 4 years ago

this solves the problem, but disabling hardwareAccelerated has serious impact on performance of app, hope it will be fixed soon

jsamr commented 4 years ago

@drb1 I do understand this is problematic. A user in the react-native-webview thread I referenced claims that putting opacity at 0.99 for the WebView might do the trick. I tested on your repo, and it works. My god, that's so utterly hackish. Here is the patch:

diff --git a/src/screens/EmbededVideoDemo.js b/src/screens/EmbededVideoDemo.js
index 1f42739..e6fa5cf 100644
--- a/src/screens/EmbededVideoDemo.js
+++ b/src/screens/EmbededVideoDemo.js
@@ -4,11 +4,16 @@ import HTML from 'react-native-render-html';

 const htmlContent = "<p style=\"text-align: left;\">The word&nbsp;<em>ocean</em>&nbsp;comes from the figure in&nbsp;<span style=\"color: #3598db;\"><a style=\"color: #3598db;\" title=\"Classical antiquity\" href=\"https://en.wikipedia.org/wiki/Classical_antiquity\">classical antiquity</a></span>,&nbsp;<a title=\"Oceanus\" href=\"https://en.wikipedia.org/wiki/Oceanus\">Oceanus</a> <small>pronounced&nbsp;</small><span class=\"IPA\" title=\"Representation in the International Phonetic Alphabet (IPA)\"><a title=\"Help:IPA/Greek\" href=\"https://en.wikipedia.org/wiki/Help:IPA/Greek\">[??kean&oacute;s]</a></span>, the elder of the&nbsp;<a class=\"mw-redirect\" title=\"Titan (mythology)\" href=\"https://en.wikipedia.org/wiki/Titan_(mythology)\">Titans</a>&nbsp;in classical&nbsp;<a title=\"Greek mythology\" href=\"https://en.wikipedia.org/wiki/Greek_mythology\">Greek mythology</a>, believed by the&nbsp;<a title=\"Ancient Greece\" href=\"https://en.wikipedia.org/wiki/Ancient_Greece\">ancient Greeks</a>&nbsp;and&nbsp;<a title=\"Ancient Rome\" href=\"https://en.wikipedia.org/wiki/Ancient_Rome\">Romans</a>&nbsp;to be the divine personification of the&nbsp;<a title=\"Sea\" href=\"https://en.wikipedia.org/wiki/Sea\">sea</a>, an enormous&nbsp;<a title=\"River\" href=\"https://en.wikipedia.org/wiki/River\">river</a>&nbsp;encircling the world.</p>\n<p style=\"text-align: center;\"><iframe src=\"https://www.youtube.com/embed/1La4QzGeaaQ\" width=\"560\" height=\"315\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"></iframe></p>\n<p style=\"text-align: left;\">Extraterrestrial oceans&nbsp;may be composed of water or other&nbsp;elements&nbsp;and&nbsp;compounds. The only confirmed large stable bodies of extraterrestrial surface&nbsp;<a class=\"mw-redirect\" title=\"Liquids\" href=\"https://en.wikipedia.org/wiki/Liquids\">liquids</a>&nbsp;are the&nbsp;<a title=\"Lakes of Titan\" href=\"https://en.wikipedia.org/wiki/Lakes_of_Titan\">lakes of Titan</a>, although there is evidence for the existence of oceans elsewhere in the&nbsp;Solar System. Early in their geologic histories,&nbsp;<a title=\"Mars\" href=\"https://en.wikipedia.org/wiki/Mars\">Mars</a>&nbsp;and&nbsp;<a title=\"Venus\" href=\"https://en.wikipedia.org/wiki/Venus\">Venus</a>&nbsp;are theorized to have had large water oceans. The&nbsp;Mars ocean hypothesis&nbsp;suggests that nearly a third of the surface of Mars was once covered by water, and a&nbsp;<a title=\"Runaway greenhouse effect\" href=\"https://en.wikipedia.org/wiki/Runaway_greenhouse_effect\">runaway greenhouse effect</a>&nbsp;may have boiled away the global ocean of Venus. Compounds such as&nbsp;<a title=\"Salt (chemistry)\" href=\"https://en.wikipedia.org/wiki/Salt_(chemistry)\">salts</a>&nbsp;and&nbsp;<a title=\"Ammonia\" href=\"https://en.wikipedia.org/wiki/Ammonia\">ammonia</a>&nbsp;dissolved in water lower its freezing point so that water might exist in large quantities in extraterrestrial environments as brine or convecting&nbsp;<a title=\"Ice\" href=\"https://en.wikipedia.org/wiki/Ice\">ice</a>. Unconfirmed oceans are speculated beneath the surface of many&nbsp;<a class=\"mw-redirect\" title=\"Dwarf planets\" href=\"https://en.wikipedia.org/wiki/Dwarf_planets\">dwarf planets</a>&nbsp;and natural satellites; notably, the ocean of the moon&nbsp;<a title=\"Europa (moon)\" href=\"https://en.wikipedia.org/wiki/Europa_(moon)\">Europa</a>&nbsp;is estimated to have over twice the water volume of Earth.</p>";

+const tagsStyles = {
+    iframe: {
+        opacity: 0.99
+    }
+}

 const EmbededVideoDemo = () => {
     return (
         <ScrollView style={{flex: 1}}>
-            <HTML html={htmlContent} imagesMaxWidth={Dimensions.get('window').width}/>
+            <HTML tagsStyles={tagsStyles} html={htmlContent} imagesMaxWidth={Dimensions.get('window').width}/>
         </ScrollView>
     );
 };

Can you confirm on your side?

drb1 commented 4 years ago

yes this also solved the issue, i think this is the best method for now.

jsamr commented 4 years ago

I am closing because there is a known workaround and the bug happens upstream. See https://stackoverflow.com/q/63171131/2779871

hrdyjan1 commented 3 years ago

Thank you for the temporary solution, still not sure how is it possible, that opacity style will fix the issue 🤷

marco2216 commented 2 years ago

The current equivalent to this solution, assuming you're using @native-html/iframe-plugin, is as follows (optionally check if is android when applying this):

renderersProps={{
  iframe: {
    webViewProps: {
      style: { opacity: 0.99 },
    },
  },
}}
Nasseratic commented 2 years ago

@marco2216 Thanks man that worked!

limeojin363 commented 9 months ago

As @marco2216 metioned, when you are using plugin(table/iframe) with HTML component containing Webview={WebView} prop, you may need renderersProps, not tagStyles. I was using @native-html/table-plugin and WebView prop like this.

import HTML from 'react-native-render-html';
import WebView from 'react-native-webview';
import TableRenderer from '@native-html/table-plugin';

// ...
  return (
    <HTML
      source={{html}} // html: Some texts..
      WebView={WebView}
      renderers={{table: TableRenderer}}
    />
  );

// ...

First didn't work for me and second did.

// import statements..

//...
  return (
    <HTML
      tagsStyles={{ // X
        table: {
          opacity: 0.99,
        },
      }}
      source={{html}}
      WebView={WebView}
      renderers={{table: TableRenderer}}
    />
  );

// ...
// import statements..

//...
  return (
    <HTML
      renderersProps={{ // O
        table: {
          webViewProps: {
            style: {opacity: 0.99},
          },
        },
      }}
      source={{html}}
      WebView={WebView}
      renderers={{table: TableRenderer}}
    />
  );

// ...