react-native-render-html icon indicating copy to clipboard operation
react-native-render-html copied to clipboard

HTML string is too long, lead to can't render the content

Open orzhtml opened this issue 7 years ago • 22 comments

Is this a bug report or a feature request?

(Write your answer here.) HTML string is too long, lead to can't render the content

Have you read the guidelines regarding bug report?

(Write your answer here.)

Have you read the documentation in its entirety?

(Write your answer here.)

Have you made sure that your issue hasn't already been reported/solved?

(Write your answer here.)

Is the bug specific to iOS or Android? Or can it be reproduced on both platforms?

(Write your answer here and specify the iOS/Android versions on which you've been able to reproduce the issue.)

Is the bug reproductible in a production environment (not a debug one)?

(Write your answer here.)

Have you been able to reproduce the bug in the provided example?

(Write your answer here.)

Environment

(Write your answer here.) React Native Environment Info: System: OS: macOS High Sierra 10.13.6 CPU: (4) x64 Intel(R) Core(TM) i7-3520M CPU @ 2.90GHz Memory: 36.11 MB / 8.00 GB Shell: 5.3 - /bin/zsh Binaries: Node: 8.11.3 - ~/.nvm/versions/node/v8.11.3/bin/node Yarn: 1.12.3 - ~/.yarn/bin/yarn npm: 6.4.1 - ~/.nvm/versions/node/v8.11.3/bin/npm Watchman: 4.7.0 - /usr/local/bin/watchman SDKs: iOS SDK: Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1 Android SDK: API Levels: 23, 24, 25, 26, 27 Build Tools: 23.0.1, 23.0.2, 23.0.3, 24.0.2, 25.0.0, 25.0.1, 25.0.2, 25.0.3, 26.0.0, 26.0.1, 26.0.2, 27.0.3 System Images: android-23 | Intel x86 Atom, android-23 | Google APIs Intel x86 Atom, android-25 | Google APIs Intel x86 Atom, android-26 | Google APIs Intel x86 Atom, android-27 | Google APIs Intel x86 Atom IDEs: Android Studio: EAP AI-171.4010489 AI-171.4010489 Xcode: 10.1/10B61 - /usr/bin/xcodebuild npmPackages: react: 16.6.1 => 16.6.1 react-native: 0.57.5 => 0.57.5 npmGlobalPackages: eslint-plugin-react-native: 3.5.0 react-native-cli: 2.0.1

Steps to Reproduce

(Write your steps here:)

1. 2. 3.

Expected Behavior

(Write what you thought would happen.)

Actual Behavior

(Write what happened. Add screencasts/screenshots!)

Reproducible Demo

(Paste the link to an example project or paste the entirety of the relevant source code. Then provide instructions to reproduce the issue.)

orzhtml avatar Dec 19 '18 03:12 orzhtml

+1

saimemre1 avatar Jan 02 '19 19:01 saimemre1

Maybe this can be helpful, When I change marginVerticals (marginbottom, margintop etc..) from 'x%' to constant values (SCREEN_HEIGHT * 0.1 or integer), problem solved.

saimemre1 avatar Jan 09 '19 12:01 saimemre1

HI @orzhtml , you didn't explain anything. What do you mean by it can't render the content ?

Is it like a crash because the HTML string is too big ? Or is it a styling problem as @saimemre1 suggested ? I'm not sure what you're talking about...

Exilz avatar Feb 11 '19 16:02 Exilz

I have a similar problem too. Short texts can render however long texts cannot render. There are still

tags in the text.

benfurkankilic avatar Feb 13 '19 08:02 benfurkankilic

I have a similar problem too. Short texts can render however long texts cannot render. There are still

tags in the text.

+1

orzhtml avatar Feb 13 '19 08:02 orzhtml

If neither of you provides an HTML string and how you're rendering your HTML (the component and how you use it), I won't be able to help.

I still have no clue what you're talking about.

Exilz avatar Feb 13 '19 08:02 Exilz

If neither of you provides an HTML string and how you're rendering your HTML (the component and how you use it), I won't be able to help.

I still have no clue what you're talking about.

For example, "&'#039;One Piece&'#039; Introduces Zoro&'#039;s New Friends " (I add a " ' " between the & and # for understanding) this is my title. I fetch this data in an API. I can convert this title " 'One Piece' Introduces Zoro's New Friends " however I also fetch a text data which contains more than 1000 characters cannot be converted. If I use text data as <HTML html='text....'/>, it can convert, but when I used with parameters it can not be converted. For example, <HTML html={this.props.text}/>

benfurkankilic avatar Feb 13 '19 10:02 benfurkankilic

If neither of you provides an HTML string and how you're rendering your HTML (the component and how you use it), I won't be able to help.

I still have no clue what you're talking about.

this.state = {
html: '<div>HTML string is too long</div><div>HTML string is too long</div><div>HTML string is too long</div><div>HTML string is too long</div><div>HTML string is too long</div><div>HTML string is too long</div><div>HTML string is too long</div><div>HTML string is too long</div><div>HTML string is too long</div><div>HTML string is too long</div><div>HTML string is too long</div><div>HTML string is too long</div><div>HTML string is too long</div><div>HTML string is too long</div><div>HTML string is too long</div><div>HTML string is too long</div><div>HTML string is too long</div><div>HTML string is too long</div><div>HTML string is too long</div><div>HTML string is too long</div>.....'
}
<HTML html={this.state.html+this.state.html+this.state.html+this.state.html+this.state.html+this.state.html+this.state.html+this.state.html+this.state.html+this.state.html+this.state.htmlthis.state.htmlthis.state.html+this.state.html+this.state.html}/>

Need a lot of HTML string

orzhtml avatar Feb 14 '19 09:02 orzhtml

If neither of you provides an HTML string and how you're rendering your HTML (the component and how you use it), I won't be able to help. I still have no clue what you're talking about.

this.state = {
html: '<div>HTML string is too long</div><div>HTML string is too long</div><div>HTML string is too long</div><div>HTML string is too long</div><div>HTML string is too long</div><div>HTML string is too long</div><div>HTML string is too long</div><div>HTML string is too long</div><div>HTML string is too long</div><div>HTML string is too long</div><div>HTML string is too long</div><div>HTML string is too long</div><div>HTML string is too long</div><div>HTML string is too long</div><div>HTML string is too long</div><div>HTML string is too long</div><div>HTML string is too long</div><div>HTML string is too long</div><div>HTML string is too long</div><div>HTML string is too long</div>.....'
}
<HTML html={this.state.html+this.state.html+this.state.html+this.state.html+this.state.html+this.state.html+this.state.html+this.state.html+this.state.html+this.state.html+this.state.htmlthis.state.htmlthis.state.html+this.state.html+this.state.html}/>

Need a lot of HTML string

Also, this does not work for me. I want to call data with props, however, it renders with<p> tags etc.

benfurkankilic avatar Feb 14 '19 10:02 benfurkankilic

I'm encountering this as well- I have a pretty large text blob (12039 characters) that is failing to load in the html view. There is no error and the height seems to be accurate, but there is no visible text.

Another detail- the text has no html tags, it's just a flat blob of text rendered in a body tag

tylerjbainbridge avatar Feb 18 '19 16:02 tylerjbainbridge

A coworker looked into this issue a little bit and found that if the content's height is over a certain number of pixels (5440px according to him), none of it will be rendered. Not sure how helpful that is in terms of diagnosing the issue, but hopefully it helps a little!

achou11 avatar Mar 11 '19 22:03 achou11

In my case a reason was in borderRadius style in html view container :

<ScrollView>
     <View style={styles.post}>
         <HTMLViewContainer html={content} />
     </View>
</ScrollView>

const styles = StyleSheet.create({
    post: {
      // borderRadius: 5, // <-- BUG
      paddingTop: 0,
      paddingBottom: 20,
      paddingLeft: 20,
      paddingRight: 20
   }
})

dmitrydudkin avatar Jul 05 '19 09:07 dmitrydudkin

This appears to be a limitation with React Native <Text> components: https://github.com/facebook/react-native/issues/19453

There is a pretty easy workaround though if you want to have a <Text> component that has very long content you can convert it to use a <TextInput> instead like so:

<TextInput multiline={true} editable={false}>
  Some very long text
</TextInput>

In order to get that sort of workaround when using this library though I think that would require some changes.

You could specify a custom renderer using the renderers prop and have a custom renderer for a <p> tag for example to render a TextInput instead, however you would have to do this for every tag you need to support, and as far as I am aware there is no way to set a custom renderer for raw text currently.

jamesovens avatar Jul 19 '19 14:07 jamesovens

Rewrite HTML to react-native, github search: react-native-orzhtml-htmlview

Don't want to switch to another component, don't comment on my new component

orzhtml avatar Aug 13 '19 14:08 orzhtml

I'm not sure why this was closed as this is still an issue in this library. Changing to another library does not fix the issue in this library (and I wouldn't want to change library for this problem when the rest of it works so well in the React Native Web project I am working on).

Really all I think we need is to have the library check when the current node is raw text to check its length. If the content length gets above a certain threshold then the wrapper it uses for the raw text should switch from using an <Text> to using a <TextInput multiline={true} editable={false}>.

This could even be an optional behaviour that is turned on by passing true to a new prop to maintain backwards compatibility.

I managed to implement a workaround for this in the library as it is today using custom renderers but it is not an ideal solution. Something like I have suggested above may work and I hope would not be too difficult to implement.

jamesovens avatar Aug 20 '19 11:08 jamesovens

I am having same issue when render a large HTML content then app will be crashed other wise it working fine I am debugging this from almost ten days but did not find any accurate answer. Can anybody help me to fix this issue. Thanks

wikramdas avatar Aug 14 '20 11:08 wikramdas

@wikramdas I am willing to investigate this to provide a hotfix; to do this I would need a full reproduction though. Could you provide a repro? Hints are available here on how to do so.

jsamr avatar Aug 14 '20 12:08 jsamr

@jsamr its quite easy to reproduce.

  1. import HTML component from this library
  2. Pass a HTML string that is longer than 7000 chars to the html prop

You will now see that the text is not rendered at all and no error is outputted to the console.

A workaround is to split the html string into chunks with a length of 6750 chars and then pass each chunk to a separate html component.

woba-ko avatar Nov 18 '20 10:11 woba-ko

@woba-ko OK. It will be "fixed" in release cycle 6.x "foundry".

jsamr avatar Nov 18 '20 21:11 jsamr

@jsamr in my case I am facing this issue on android devices which are less than 7.0 android version. I am loading a big html like wikipedia's article and showing it in the app whenever it renders my app goes stuck and after 5 seconds it crashed. I am using ^4.2.5 version of this library. Correct me if I am doing something wrong. This is the issue I am facing.

wikramdas avatar Dec 14 '20 08:12 wikramdas