Re: sXBL issue -- bindings getting notified when the bound element is inserted into a document

This is a somewhat belated reply to Jim's reply [1] to my original mail about 
the issue of XBL bindings being notified when a node is inserted into the 
document [2].

I made an attempt to design things using DOMNodeInsertedIntoDocument, and 
discovered two major problems.  First, and less importantly, event firing order 
in the DOM spec is badly underdefined (so it's not clear in which order 
DOMNodeInsertedIntoDocument is fired on the nodes of a subtree that's inserted 
into the document).  Second, it's possible for DOMNodeInsertedIntoDocument to 
fire on a node that's not in the document anymore.

Indeed, consider the following simple scenario:

A)  There is a capturing DOMNodeInsertedIntoDocument listener on the root
     element that simply does:

       var node = event.target;
       node.parentNode.removeChild(node);

B)  A node is inserted as a child of this root.

In this case, the order of event firing (for simplicity, I list just the 
DOMNodeInsertedIntoDocument and DOMNodeRemovedFromDocument events; there are 
also some DOMNodeInserted and DOMNodeRemoved events flying about) is the 
following (the two nodes involved will be called "root" and "child"):

1) Capturing DOMNodeInsertedIntoDocument event on root
2) Capturing DOMNodeRemovedFromDocument event on root
3) At-target DOMNodeRemovedFromDocument event on child
4) At-target DOMNodeInsertedIntoDocument event on child

Note that by step 4 the child isn't actually in the document anymore.

Worse, given the constraints that capturing exists, that all events capture, 
that any event listener is allowed to modify the DOM, there is no way to avoid 
this scenario if a DOM event is used as the trigger for "we're completely set up 
now".

I'm frankly somewhat at a loss as to what can be done about this.  My initial 
temptation is to create some Mozilla-XBL specific syntax for the binding to be 
notified when a node is inserted into the document and all relevant mutation 
events have fired without the node being removed in the process...

-Boris

[1] http://lists.w3.org/Archives/Public/www-svg/2004Oct/0130.html
[2] http://lists.w3.org/Archives/Public/www-svg/2004Oct/0127.html

Received on Friday, 18 March 2005 04:36:04 UTC