Mithril.js: Mithril throws an error when two or more sibling components render content via m.trust

Created on 31 Jul 2019  路  7Comments  路  Source: MithrilJS/mithril.js

When 2 or more instances of a component that renders m.trust() content are rendered, changing the html string passed to m.trust between redraws will cause Mithril to throw an error.

Mithril version: 2.0.3

Browser and OS: All

Code

flems example

Steps to Reproduce

  1. In the flems example above, click one 'Toggle' button
  2. Then click the other toggle button.

Expected Behavior

Mithril should render the content.

Current Behavior

Throws the error: Cannot read property 'length' of undefined

Core Bug

Most helpful comment

I also experience the same bug (but not always reproducible!) whereas my tree just contains a single DOM element that uses m.trust. The error occurs in render.js:

    function removeHTML(parent, vnode) {
        for (var i = 0; i < vnode.instance.length; i++) {
            parent.removeChild(vnode.instance[i])
        }
    }

Is there anything we can do to help fix these bugs faster in the release version?

BTW I can also confirm that v2.0.1 was working OK.

All 7 comments

That's weird. Thanks for the report!

vnode.instance should now always be an array for vnodes Mithril created. I wonder if mistakenly a new vnode got passed for an old one somewhere down the line when I updated that code...

I can confirm that there is an issue with vnode.instance. Few days ago I wrote about it in gitter chat. In my code I am using m.trust(outputHtml) where outputHtml comes from server. The error was something like "vnode.instance is undefined". This happens in v2.0.3, but not in v2.0.1.

I also experience the same bug (but not always reproducible!) whereas my tree just contains a single DOM element that uses m.trust. The error occurs in render.js:

    function removeHTML(parent, vnode) {
        for (var i = 0; i < vnode.instance.length; i++) {
            parent.removeChild(vnode.instance[i])
        }
    }

Is there anything we can do to help fix these bugs faster in the release version?

BTW I can also confirm that v2.0.1 was working OK.

I'm also receiving this error in my app on a view that uses m.trust. In my case it can be easily reproduced by explicitly triggering a redraw via m.redraw. Can also confirm 2.0.1 does not have the issue.

Same issue here.

I render an svg icon using m.trust, the error occurs when I replace the svg icon with a different in subsequent renders of the component. It throws at the same place as for erikvullings, in the for loop, because vnode.instance is undefined.

I can also confirm v2.0.1 did not have the issue.

Same error in Tutanota currently.
Is there a patch/fix which one can try to apply?

I have the same issue with m.trust and thought I was going crazy until I found this official example suffers the same fate. Simply and add something in the first heading.

Thanks @cruzmiraback @pdehne I'm going to try and rollback to 2.0.1 for now until a fix is in place.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pygy picture pygy  路  4Comments

dhinesh03 picture dhinesh03  路  4Comments

mke21 picture mke21  路  3Comments

simov picture simov  路  4Comments

ozgurrgul picture ozgurrgul  路  3Comments