mithril.js: unmount fails due to null node when dom.nextSibling is null
sometimes when unmounting a view, removeNodeFromDOM fails when dom.nextSibling is null as it does not check that node is not null, causing the mount of the next view to also fail.
my changes to resolve the issue
--- a/root/js/mithril-1.1.1.js
+++ b/root/js/mithril-1.1.1.js
@@ -799,8 +799,10 @@ var coreRenderer = function($window) {
}
}
function removeNodeFromDOM(node) {
- var parent = node.parentNode
- if (parent != null) parent.removeChild(node)
+ if(node != null) {
+ var parent = node.parentNode;
+ if (parent != null) parent.removeChild(node)
+ }
}
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 22 (16 by maintainers)
@isiahmeadows will do, i can preproduce fairly quickly.
@iainmcampbell Probably so, since we didn’t realize until now it was creating hard-to-debug exceptions for people in cases that it obviously shouldn’t be. Most of the discussion up to this point has been just questions of API ergonomics and a few specific edge cases, not indirectly causing DOM exceptions through a seemingly separate public API that visibly should be handling that case.
Also props to @porsager for making it so quick and easy to test hypotheses about bugs. Flems.io rules!
Not sure if this is quite the same thing, but whatever it is I’ve managed to reproduce it: https://jsfiddle.net/qhprw0ku/7/. The exact error I’m getting is
Uncaught DOMException: Failed to execute 'removeChild' on 'Node': The node to be removed is no longer a child of this node. Perhaps it was moved in a 'blur' event handler?I only get an error in Chrome 59, not Firefox 54 or Safari 10.Call stack is
removeNodeFromDOM→continuation→removeNodeand so on.To reproduce: create an
<input>, addonfocusandonblurhandlers, that add/remove akeydownevent, that triggers a route change.