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
Mithril should render the content.
Throws the error: Cannot read property 'length' of undefined
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
Thanks @cruzmiraback @pdehne I'm going to try and rollback to 2.0.1 for now until a fix is in place.
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 inrender.js: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.