Skip to content

Blaze.remove() destroys DOM before calling onDestroyed() #372

@michaelcbrook

Description

@michaelcbrook

Hi,

This problem only happens when you explicitly call Blaze.remove(view), but this piece of code causes the DOM to be destroyed before calling the onDestroyed callback.

if (range.attached && ! range.parentRange)
range.detach();
range.destroy();

The way it should work (and how it works when a view is destroyed by any other means) is the DOM is destroyed after the onDestroyed callback is called.

The solution, as far as I can tell, is to simply reverse the order of range.detach() and range.destroy().

 range.destroy();
 if (range.attached && ! range.parentRange)
   range.detach();

In my testing, this fixes the problem.

Note that this problem only applies to explicit calls to Blaze.remove(view). Destroying by other means all appears to work correctly.

Related

This problem, however, also seems to appear in the blaze-hot package.

view._domrange.detach();
view._domrange.destroy();

This problem occurs when updating the JS code of a template. When a hot module reload is performed on the template, the onDestroyed callback is called, but if it tries to reference the DOM, it will throw an error.

The solution is the same as the above, to switch the order of detach() and destroy(). When that is changed, the problem is fixed.

Let me know if this is not the right place to post the issue about blaze-hot.

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions