Skip to content

Need help with "Failed to execute 'insertBefore' on 'Node'" errors. #2885

@EverettMcKay

Description

@EverettMcKay

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:

  1. What is the cause of this error? The problem has apparently come up many times before, but I'm not quite following the prior discussions. Is there a list of top causes?
  2. Is there a way to narrow down the specific cause? Both the error message line number and call stack are pretty useless here. An error message pops up in the console, but it appears to be displayed asynchronously, so I can't seem to get the error to display while stepping through in the debugger.
  3. What is the work around? I tried to make sure my keys are unique, but that has got me nowhere. Aside from keys, is there any other common solution?

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: QuestionFor issues that are purely questions about Mithril, not necessarily bug reports or suggestions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions