Need help with "Failed to execute 'insertBefore' on 'Node'" errors. #2909
Replies: 3 comments
-
I think I just got lucky. The problem seems to be with one of the svg icons. This works:
But this doesn't:
Suspecting the polygon tag. If so, would be great to issue a run-time warning instead of an insertBefore error. |
Beta Was this translation helpful? Give feedback.
-
As in the other issue, we could help you better if you provided us a repro. The error message makes me thing that something other that Mithril modifies with the DOM, resulting in problems when updating. |
Beta Was this translation helpful? Give feedback.
-
After a long delay, I was planning on building a test program to illustrate this problem, but the problem resurfaced again this week big time, making my app inoperable. So, I had to look at it again and got lucky. First, here is what is logged when the problem is happening (you will see many of these):
There were actually two problems related to handling svgs dynamically:
My app has the ability to let users select icons, which was getting messed up with a mixture of old and new, but only when the icons were svgs. Before, I had a key (based on the state, which determined the icon) on a parent div. I changed that to putting a key directly on the svg (based on the icon). For whatever reason, I didn’t try keys directly on the svgs before.
A common situation might be to change the number of icons from 10 to 7 (or any other combination.) The old icons (8 – 10) would often still be displayed after the change in though they were removed from the virtual dom. To clear these out, I temporarily replace all existing icons with blanks, then draw the new ones. This results in a flash but otherwise works as expected. Recommendations: It would be great if we could:
A happy ending. Thank you for your patience. |
Beta Was this translation helpful? Give feedback.
-
Hi,
I'm getting a "Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node." error, and as a result my app isn't rendering correctly. Of course, my app doesn't have any insertBefore calls, so I assume this is coming from the Mithril difference engine.
A few questions:
Since I don't know that the exact problem, I can't narrow it down enough to give code samples. Generally, what I am doing is presenting a list of svg icons (think star ratings) and updating their color and icon type (empty, filled in) based on the current state. Oddly, if I hardwire their color and type, the problem goes away. So the problem only happens when I update their presentation dynamically based on clicking.
Forcing a refresh results in the component drawing correctly. I had hoped that calling m.redraw() might fix the problems by redrawing the icons, but no luck there.
Finally, in the past I have been able to get problems like this to go away with either calling redraw or changing the keys. Neither solution appears to work in this case.
Beta Was this translation helpful? Give feedback.
All reactions