React-native-render-html: TaskQueue: Error with task : undefined is not and object (evaluating '_attribs.style')

Created on 7 Nov 2017  路  12Comments  路  Source: meliorence/react-native-render-html

Hi again,

switching from 3.4.0 to 3.5.0, I get this issue:
capture d ecran 2017-11-07 a 10 30 47

Which points to this line: https://github.com/archriss/react-native-render-html/blob/master/src/HTML.js#L350

I didn't have this issue with previous versions, my content and styles didn't change, so I don't know what I should check.

Most helpful comment

@yjb94 @enguerranws please try the v3.5.1 branch, and specifically this commit.

I guess it should fix it in a clean way.

All 12 comments

I guess it comes form the HTML I provide.

I did a simple test:

<HTML
                  html={`
        <ul>
            <li>Easy</li>
            <li>Peasy</li>
            <li><div style="background-color:red;width:50px;height:50px;"></div></li>
            <li>Lemon</li>
            <li>Squeezy</li>
        </ul>

    `}
                  tagsStyles={ HTMLStyles }
                />

This throws the error.

When I replace the content with :

<HTML
                  html={'<p>test</p>'}
                  tagsStyles={ HTMLStyles }
                />

or :

<HTML
                  html={'<p>Here is an <em>ul with <i>li</i></em> tag</p>'}
                  tagsStyles={ HTMLStyles }
                />

There's no error.

I don't know if this is a good way to solve this, anyway, I did a workaround by adding a simple check in HTML.js:

                         if(typeof(attribs) !== 'undefined') {
                            if (!attribs.style) {
                                child.attribs.style = cssObjectToString(textChildrenInheritedStyles);
                            } else {
                                child.attribs.style = cssObjectToString({
                                    ...textChildrenInheritedStyles,
                                    ...cssStringToObject(child.attribs.style)
                                });
                            }
                        }

From what I see, it works and doesn't break everything. But I'm pretty sure this is not a clean solution to this issue :)

Thanks for the workaround. I need some time to dive more into this because attribs should never really be undefined. An empty object, at least.

I'll keep you posted once I know more about this issue.

@Exilz Thanks! Let me know if I can help you.

+1

if(attribs) { if (!attribs.style) { child.attribs.style = cssObjectToString(textChildrenInheritedStyles); } else { child.attribs.style = cssObjectToString({ ...textChildrenInheritedStyles, ...cssStringToObject(child.attribs.style) }); } }

i just managed to add a temporal code for exception..

In my case, the html code was

<p><img src='~~~~~'>SOME_TEXT</p> //didn't work
<p><img src='~~~~~'></p><p>SOME_TEXT</p> //worked

can this help? @Exilz

Yeah, your example did help me figure out what's going on.
I think it's just a minor issue, I should be releasing a fix later today.

@yjb94 @enguerranws please try the v3.5.1 branch, and specifically this commit.

I guess it should fix it in a clean way.

Great! it's fixed! thx @Exilz

Yeah, thanks @Exilz, I'll test it asap!

@Exilz From what I see, it fixes the issue. When will it be available in master?

It's now available on master and on npm. I was waiting for your input. :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gabriel-tentaculo picture gabriel-tentaculo  路  7Comments

Aparus picture Aparus  路  3Comments

fahadhaq picture fahadhaq  路  6Comments

sayem314 picture sayem314  路  6Comments

duansiyu picture duansiyu  路  4Comments