Another way to do this is that in mutation method macro, prevent `oldNode` from being added to the doc frag, and after that, insert the doc frag before `oldNode`, finally remove `oldNode`. No recursive finding of next sibling is needed this way.
> On Jan 16, 2015, at 1:37 PM, Glen Huang <curvedm...@gmail.com> wrote: > > Currently, for `oldNode.replaceWith(…collection)`, if `collection` is array > of multiple nodes, and `oldNode` is in `collection`, after the mutation > method macro, `oldNode` lives in a doc frag. So in the replace algorithm, > `parent` is the doc frag, `node` is also the doc frag, an > `HierarchyRequestError` is thrown. > > I wonder if an error really should be thrown in this case? Intuitively, > `collection` should be inserted before `oldNode`’s original next sibling. > > For example: > > ``` > <div id="d1"></div> > <div id="d2"></div> > <div id="d3"></div> > <div id="d4"></div> > ``` > > Imagine `oldNode` is #d2, `collection` is [#d1,#d2,#d4], executing > `oldNode.replaceWith(…collection)` should give > > ``` > <div id="d1"></div> > <div id="d2"></div> > <div id="d4"></div> > <div id="d3"></div> > ``` > > Instead of throwing an error. > > To make it this work, before executing the mutation method macro, `oldNode`’s > parent should be saved. It’s next sibling should also be saved, but the next > sibling need to be found recursively if it happens to be in `collection` too. > > So, If I’m not wrong, this edge case could work in principle. I’m not sure if > there is any interest to allow this?